#include <bits/stdc++.h>
const int maxn = 1e6 + 10;
struct Edge {
  int v, next;
  Edge() {}
  Edge(int next, int v) : next(next), v(v) {}
} e[maxn];
int n, m, S, T;
int head[maxn], cnt;
int dp[maxn], q[maxn * 2], in[maxn];
bool vis[maxn];
void AddEdge(int u, int v) {
  e[++cnt] = Edge(head[u], v);
  head[u] = cnt;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1, u, v; i <= m; i++) {
    scanf("%d%d", &u, &v);
    AddEdge(v, u);
    in[u]++;
  }
  scanf("%d%d", &S, &T);
  for (int i = 1; i <= n; i++) dp[i] = 1e9;
  dp[T] = 0;
  q[n] = T;
  for (int l = n, r = n; l <= r; l++) {
    int u = q[l];
    if (vis[u]) continue;
    vis[u] = 1;
    for (int i = head[u], v; v = e[i].v, i; i = e[i].next)
      if (!--in[v]) {
        if (dp[u] < dp[v]) {
          dp[v] = dp[u];
          q[l--] = v;
        }
      } else if (dp[u] + 1 < dp[v]) {
        dp[v] = dp[u] + 1;
        q[++r] = v;
      }
  }
  printf("%d\n", dp[S] < 1e9 ? dp[S] : -1);
  return 0;
}
