~/algor $ cat problems/eng-qisqa-yol
Shortest path
Medium
2000 ms
128 MB
45%
A city has $n$ intersections and $m$ two-way streets. The intersections are numbered from $1$ to $n$. Each street joins two intersections, and driving along it takes $1$ minute. Find the smallest number of minutes needed to get from intersection $1$ to intersection $n$. If it is impossible, print $-1$.
Input
The first line contains two integers: $n$ and $m$. Each of the next $m$ lines contains two positive integers: $u$ and $v$ — the intersections joined by a street.
Output
One integer — the smallest number of minutes or $-1$.
Note
$2 \le n \le 10^{5}$
$0 \le m \le 2 * 10^{5}$
$1 \le u, v \le n$
Examples
Input #1
4 4 1 2 2 3 3 4 1 3
Output #1
2
Input #2
3 1 1 2
Output #2
-1