eolymp
bolt
Try our new interface for solving problems
Problems

Algorithm Complexity

Algorithm Complexity

Petr wants to use his own algorithm to solve a very important problem for a directed graph G with n vertices and m arcs. Unfortunately, Petr cannot calculate a complexity of his algorithm. He only knows that the complexity depends on the order of growth of value F(n) which denotes the number of walks of length n from vertex s to vertex t in G. Petr wants to bound F(n) with a polynomial of minimal degree, that is, to find the minimal non-negative integer k such that for some fixed number C inequality F(n) ≤ C * nk holds for any positive n.

Help him to do it.

Input

The first line contains four integers n, m, s, t (1n, m105). The vertices are numbered from 1 to n. Each of the next m lines contains two space-separated integers - numbers of starting and ending vertices of the current arc. The graph doesn't contain multiple arcs but may contain loops.

Output

Output the minimal integer k that satisfies the problem statement. If there are no such numbers, output "-1".

Time limit 1 second
Memory limit 128 MiB
Input example #1
2 3 1 2
1 1
1 2
2 2
Output example #1
1
Input example #2
3 6 1 2
1 2
2 1
1 3
3 1
2 3
3 2
Output example #2
-1
Author Ivan Burmistrov
Source 2009 Petrozavodsk Winter Session, Ural SU Contest, February 4, Problem C