#include<bits/stdc++.h>
using namespace std;
const int maxn = 2e4 + 10;
int n, m, s, t;
int h[maxn], nxt[maxn], to[maxn], cnt;
int dis[maxn];
bool vis[maxn], point[maxn];
queue<int> q;
int read() {
int x = 0, y = 1;
char c = getchar();
while (c > '9' || c < '0') {
if (c == '0')y = -1;
c = getchar();
}
while (c >= '0' && c <= '9') {
x = x * 10 + c - '0';
c = getchar();
}
return x * y;
}
void add(int a, int b) {
to[++cnt] = b;
nxt[cnt] = h[a];
h[a] = cnt;
}
void BFS() {
vis[t] = true;
q.push(t);
while (!q.empty()) {
int u = q.front();
q.pop();
for (int i = h[u]; i != -1; i = nxt[i]) {
int v = to[i];
if (!vis[v]) vis[v] = true, q.push(v);
}
}
}
void check() {
memcpy(point, vis, sizeof vis);
for (int i = 1; i <= n; i++) {
if (!vis[i]) {
for (int j = h[i]; ~j; j = nxt[j]) {
int v = to[j];
if (point[v]) point[v] = false;
}
}
}
}
void Solve() {
q.push(t);
while (!q.empty()) {
int u = q.front();
q.pop();
for (int i = h[u]; i != -1; i = nxt[i]) {
int v = to[i];
if (point[v]) {
point[v] = false;
q.push(v);
dis[v] = dis[u] + 1;
if (v == s) return;
}
}
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
memset(h, -1, sizeof h);
n = read(), m = read();
for (int i = 1; i <= m; i++) {
int x, y;
x = read(), y = read();
if (x == y) continue;
add(y, x);
}
s = read(), t = read();
BFS();
check();
if (!point[s]) cout << "-1", exit(0);
Solve();
cout << dis[s];
return 0;
}