Use a loop variable km, loop through each km in distances,  and only copy those values where km <= 5.

Make sure to type km for km in distances if km <= 5.