IntermediateRating 1300
Fewest Hops
Print the minimum number of edges on a path from 1 to n in an undirected graph, or -1.
Input
n m, then m lines 'u v'.
Output
A number.
Sample 1
Input
5 5 1 2 2 3 3 5 1 4 4 5
Output
2
Sample 2
Input
3 1 1 2
Output
-1
Output appears here