Question
Night Bus Stops

A night bus network connects stops with direct two-way routes. Each route takes exactly one ride. A student starts at stop A and wants to reach stop B.

Find the minimum number of rides needed, or print -1 if the destination cannot be reached.

The twist: the route with fewer intermediate stops is not always obvious from the input order.

Input

The first line contains four integers KaTeX can only parse string typed expression, KaTeX can only parse string typed expression, KaTeX can only parse string typed expression, and KaTeX can only parse string typed expression — the number of stops, routes, start stop, and destination stop.

Each of the next KaTeX can only parse string typed expression lines contains two integers KaTeX can only parse string typed expression and KaTeX can only parse string typed expression, meaning there is a two-way bus route between stops KaTeX can only parse string typed expression and KaTeX can only parse string typed expression.

Output

Print a single integer — the minimum number of rides from KaTeX can only parse string typed expression to KaTeX can only parse string typed expression, or KaTeX can only parse string typed expression if unreachable.

Example
Example 1:
Input
6 6 1 6

1 2
2 3
3 6
1 4
4 5
5 6
Output
3
Explanation
One shortest route is KaTeX can only parse string typed expression.

Example 2:
Input
5 3 1 5

1 2
2 3
4 5
Output
-1
Explanation
Stop KaTeX can only parse string typed expression is not reachable from stop KaTeX can only parse string typed expression.

Online