#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000005;
int n, m, s, t;
vector<int> g[maxn];
int dp[maxn], dg[maxn];
bool vis[maxn];
deque<int> que;
int bfs(int s, int t) {
  memset(dp, -1, sizeof(dp));
  memset(vis, false, sizeof(vis));
  while (!que.empty()) que.pop_back();
  dp[t] = 0;
  que.push_back(t);
  while (!que.empty()) {
    int u = que.front();
    que.pop_front();
    if (vis[u]) continue;
    vis[u] = true;
    if (u == s) return dp[s];
    for (int i = 0; i < (int)g[u].size(); i++) {
      int v = g[u][i];
      if (!(--dg[v])) {
        if (dp[u] < dp[v] || dp[v] == -1) {
          dp[v] = dp[u];
          que.push_front(v);
        }
      } else if (dp[v] == -1) {
        dp[v] = dp[u] + 1;
        que.push_back(v);
      }
    }
  }
  return -1;
}
int main() {
  while (scanf("%d%d", &n, &m) != EOF) {
    int u, v;
    for (int i = 1; i <= n; i++) g[i].clear();
    memset(dg, 0, sizeof(dg));
    for (int i = 0; i < m; i++) {
      scanf("%d%d", &u, &v);
      g[v].push_back(u);
      dg[u]++;
    }
    scanf("%d%d", &s, &t);
    printf("%d\n", bfs(s, t));
  }
  return 0;
}
