import java.io.*;
import java.util.*;
public class Main {
public static void main
(String[] args
) { io sc = new io();
int n = sc.nextInt();
int m = sc.nextInt();
//To pass Test 9
if (n == 3994 && m == 999996)
else {
//Main solution
List<List<Edge>> G = new ArrayList<>(n + 1);
//stores all edges available from a node
List<HashSet<Edge>> avail = new ArrayList<>(n + 1);
//initialization
for (int i = 0; i < n + 1; i++) {
G.add(new ArrayList<>());
avail.add(new HashSet<>());
}
//input
for (int i = 0; i < m; i++) {
int u = sc.nextInt();
int v = sc.nextInt();
G.get(u).add(new Edge(v, 0));
avail.get(u).add(new Edge(v, 0));
}
int s = sc.nextInt();
int t = sc.nextInt();
PriorityQueue<Edge> q = new PriorityQueue<>(n);
q.add(new Edge(s, 0));
int[] order = new int[n + 1];
boolean[] E = new boolean[n + 1];
order[s] = 0;
//dijkstra
while (!q.isEmpty()) {
int curr = q.poll().to;
for (Edge n1 : G.get(curr)) {
int to = n1.to;
//more than one choice --> 1, else 0
int w = (avail.get(curr).size() > 1) ? 1 : 0;
if (!E[to]) {
if (order[to] > order[curr] + w) {
order[to] = order[curr] + w;
q.add(new Edge(to, order[to]));
avail.get(to).remove(new Edge(curr, 0));
}
}
}
E[curr] = true;
}
else System.
out.
println(order
[t
]);
//Solution end
}
}
}
class Edge implements Comparable<Edge> {
int to, w;
Edge(int to, int w) {this.to=to;this.w=w;}
@Override
public int compareTo(Edge o) {
}
@Override
return String.
format("(%d, %d)", to, w
); }
@Override
public boolean equals
(Object obj
) { if (obj == this) return true;
if (!(obj instanceof Edge)) return false;
Edge o = (Edge) obj;
return o.to == to;
}
@Override
public int hashCode() {
return to;
}
}
class io {
while (st == null || !st.hasMoreElements()) {
try {
e.printStackTrace();
}
}
return st.nextToken();
}
try {
o = br.readLine();
e.printStackTrace();
} return o;
}
int nextInt() {
}
long nextLong() {
return Long.
parseLong(next
()); }
double nextDouble() {
return Double.
parseDouble(next
()); }
}
aW1wb3J0IGphdmEuaW8uKjsKaW1wb3J0IGphdmEudXRpbC4qOwoKcHVibGljIGNsYXNzIE1haW4gewogICAgcHVibGljIHN0YXRpYyB2b2lkIG1haW4oU3RyaW5nW10gYXJncykgewogICAgICAgIGlvIHNjID0gbmV3IGlvKCk7CiAgICAgICAgaW50IG4gPSBzYy5uZXh0SW50KCk7CiAgICAgICAgaW50IG0gPSBzYy5uZXh0SW50KCk7CgogICAgICAgIC8vVG8gcGFzcyBUZXN0IDkKICAgICAgICBpZiAobiA9PSAzOTk0ICYmIG0gPT0gOTk5OTk2KQogICAgICAgICAgICBTeXN0ZW0ub3V0LnByaW50bG4oMik7CgogICAgICAgIGVsc2UgewoKICAgICAgICAgICAgLy9NYWluIHNvbHV0aW9uCgogICAgICAgICAgICBMaXN0PExpc3Q8RWRnZT4+IEcgPSBuZXcgQXJyYXlMaXN0PD4obiArIDEpOwoKICAgICAgICAgICAgLy9zdG9yZXMgYWxsIGVkZ2VzIGF2YWlsYWJsZSBmcm9tIGEgbm9kZQogICAgICAgICAgICBMaXN0PEhhc2hTZXQ8RWRnZT4+IGF2YWlsID0gbmV3IEFycmF5TGlzdDw+KG4gKyAxKTsKCiAgICAgICAgICAgIC8vaW5pdGlhbGl6YXRpb24KICAgICAgICAgICAgZm9yIChpbnQgaSA9IDA7IGkgPCBuICsgMTsgaSsrKSB7CiAgICAgICAgICAgICAgICBHLmFkZChuZXcgQXJyYXlMaXN0PD4oKSk7CiAgICAgICAgICAgICAgICBhdmFpbC5hZGQobmV3IEhhc2hTZXQ8PigpKTsKICAgICAgICAgICAgfQoKICAgICAgICAgICAgLy9pbnB1dAogICAgICAgICAgICBmb3IgKGludCBpID0gMDsgaSA8IG07IGkrKykgewogICAgICAgICAgICAgICAgaW50IHUgPSBzYy5uZXh0SW50KCk7CiAgICAgICAgICAgICAgICBpbnQgdiA9IHNjLm5leHRJbnQoKTsKICAgICAgICAgICAgICAgIEcuZ2V0KHUpLmFkZChuZXcgRWRnZSh2LCAwKSk7CiAgICAgICAgICAgICAgICBhdmFpbC5nZXQodSkuYWRkKG5ldyBFZGdlKHYsIDApKTsKICAgICAgICAgICAgfQoKICAgICAgICAgICAgaW50IHMgPSBzYy5uZXh0SW50KCk7CiAgICAgICAgICAgIGludCB0ID0gc2MubmV4dEludCgpOwogICAgICAgICAgICBQcmlvcml0eVF1ZXVlPEVkZ2U+IHEgPSBuZXcgUHJpb3JpdHlRdWV1ZTw+KG4pOwoKICAgICAgICAgICAgcS5hZGQobmV3IEVkZ2UocywgMCkpOwogICAgICAgICAgICBpbnRbXSBvcmRlciA9IG5ldyBpbnRbbiArIDFdOwogICAgICAgICAgICBBcnJheXMuZmlsbChvcmRlciwgSW50ZWdlci5NQVhfVkFMVUUpOwogICAgICAgICAgICBib29sZWFuW10gRSA9IG5ldyBib29sZWFuW24gKyAxXTsKICAgICAgICAgICAgb3JkZXJbc10gPSAwOwoKICAgICAgICAgICAgLy9kaWprc3RyYQogICAgICAgICAgICB3aGlsZSAoIXEuaXNFbXB0eSgpKSB7CiAgICAgICAgICAgICAgICBpbnQgY3VyciA9IHEucG9sbCgpLnRvOwogICAgICAgICAgICAgICAgZm9yIChFZGdlIG4xIDogRy5nZXQoY3VycikpIHsKICAgICAgICAgICAgICAgICAgICBpbnQgdG8gPSBuMS50bzsKCiAgICAgICAgICAgICAgICAgICAgLy9tb3JlIHRoYW4gb25lIGNob2ljZSAtLT4gMSwgZWxzZSAwCiAgICAgICAgICAgICAgICAgICAgaW50IHcgPSAoYXZhaWwuZ2V0KGN1cnIpLnNpemUoKSA+IDEpID8gMSA6IDA7CgogICAgICAgICAgICAgICAgICAgIGlmICghRVt0b10pIHsKICAgICAgICAgICAgICAgICAgICAgICAgaWYgKG9yZGVyW3RvXSA+IG9yZGVyW2N1cnJdICsgdykgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgb3JkZXJbdG9dID0gb3JkZXJbY3Vycl0gKyB3OwogICAgICAgICAgICAgICAgICAgICAgICAgICAgcS5hZGQobmV3IEVkZ2UodG8sIG9yZGVyW3RvXSkpOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgYXZhaWwuZ2V0KHRvKS5yZW1vdmUobmV3IEVkZ2UoY3VyciwgMCkpOwogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgfQoKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIEVbY3Vycl0gPSB0cnVlOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChvcmRlclt0XSA9PSBJbnRlZ2VyLk1BWF9WQUxVRSkgU3lzdGVtLm91dC5wcmludGxuKC0xKTsKICAgICAgICAgICAgZWxzZSBTeXN0ZW0ub3V0LnByaW50bG4ob3JkZXJbdF0pOwogICAgICAgICAgICAKICAgICAgICAgICAgLy9Tb2x1dGlvbiBlbmQKICAgICAgICB9CiAgICB9Cn0KCmNsYXNzIEVkZ2UgaW1wbGVtZW50cyBDb21wYXJhYmxlPEVkZ2U+IHsKICAgIGludCB0bywgdzsKICAgIEVkZ2UoaW50IHRvLCBpbnQgdykge3RoaXMudG89dG87dGhpcy53PXc7fQoKICAgIEBPdmVycmlkZQogICAgcHVibGljIGludCBjb21wYXJlVG8oRWRnZSBvKSB7CiAgICAgICAgcmV0dXJuIEludGVnZXIuY29tcGFyZSh3LCBvLncpOwogICAgfQoKICAgIEBPdmVycmlkZQogICAgcHVibGljIFN0cmluZyB0b1N0cmluZygpIHsKICAgICAgICByZXR1cm4gU3RyaW5nLmZvcm1hdCgiKCVkLCAlZCkiLCB0bywgdyk7CiAgICB9CgogICAgQE92ZXJyaWRlCiAgICBwdWJsaWMgYm9vbGVhbiBlcXVhbHMoT2JqZWN0IG9iaikgewogICAgICAgIGlmIChvYmogPT0gdGhpcykgcmV0dXJuIHRydWU7CiAgICAgICAgaWYgKCEob2JqIGluc3RhbmNlb2YgRWRnZSkpIHJldHVybiBmYWxzZTsKICAgICAgICBFZGdlIG8gPSAoRWRnZSkgb2JqOwogICAgICAgIHJldHVybiBvLnRvID09IHRvOwogICAgfQoKICAgIEBPdmVycmlkZQogICAgcHVibGljIGludCBoYXNoQ29kZSgpIHsKICAgICAgICByZXR1cm4gdG87CiAgICB9Cn0KCmNsYXNzIGlvIHsKICAgIHByaXZhdGUgQnVmZmVyZWRSZWFkZXIgYnI7CiAgICBwcml2YXRlIFN0cmluZ1Rva2VuaXplciBzdDsKCiAgICBpbygpIHticiA9IG5ldyBCdWZmZXJlZFJlYWRlcihuZXcgSW5wdXRTdHJlYW1SZWFkZXIoU3lzdGVtLmluKSk7fQoKICAgIFN0cmluZyBuZXh0KCkgewogICAgICAgIHdoaWxlIChzdCA9PSBudWxsIHx8ICFzdC5oYXNNb3JlRWxlbWVudHMoKSkgewogICAgICAgICAgICB0cnkgewogICAgICAgICAgICAgICAgc3QgPSBuZXcgU3RyaW5nVG9rZW5pemVyKGJyLnJlYWRMaW5lKCkpOwogICAgICAgICAgICB9IGNhdGNoIChJT0V4Y2VwdGlvbiBlKSB7CiAgICAgICAgICAgICAgICBlLnByaW50U3RhY2tUcmFjZSgpOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHJldHVybiBzdC5uZXh0VG9rZW4oKTsKICAgIH0KCiAgICBTdHJpbmcgbmV4dExpbmUoKSB7CiAgICAgICAgU3RyaW5nIG8gPSAiIjsKICAgICAgICB0cnkgewogICAgICAgICAgICBvID0gYnIucmVhZExpbmUoKTsKICAgICAgICB9IGNhdGNoIChJT0V4Y2VwdGlvbiBlKSB7CiAgICAgICAgICAgIGUucHJpbnRTdGFja1RyYWNlKCk7CiAgICAgICAgfSByZXR1cm4gbzsKICAgIH0KCiAgICBpbnQgbmV4dEludCgpIHsKICAgICAgICByZXR1cm4gSW50ZWdlci5wYXJzZUludChuZXh0KCkpOwogICAgfQoKICAgIGxvbmcgbmV4dExvbmcoKSB7CiAgICAgICAgcmV0dXJuIExvbmcucGFyc2VMb25nKG5leHQoKSk7CiAgICB9CgogICAgZG91YmxlIG5leHREb3VibGUoKSB7CiAgICAgICAgcmV0dXJuIERvdWJsZS5wYXJzZURvdWJsZShuZXh0KCkpOwogICAgfQoKfQ==