AdvancedRating 1600
Snakes and Ladders
On a board of squares 1 … n you start on square 1 and roll a die (1–6) each turn. Landing on the bottom of a ladder or the head of a snake moves you to its other end. Print the fewest rolls to reach square n, or -1.
Input
n and k; then k lines 'from to' for ladders and snakes.
Output
One integer.
Sample 1
Input
36 4 2 15 5 7 9 27 18 29
Output
4
Sample 2
Input
100 0
Output
17
Output appears here