#include <bits/stdc++.h>
using namespace std;
const int inf = (1 << 30);
const int MAXN = 1000010;
int n, m;
int s, t;
vector<int> in[MAXN], out[MAXN];
int cnt[MAXN];
int dp[MAXN];
bool vis[MAXN];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    out[u].push_back(v);
    in[v].push_back(u);
    cnt[u]++;
  }
  scanf("%d%d", &s, &t);
  for (int i = 1; i <= n; i++) {
    dp[i] = inf;
  }
  deque<int> dq;
  dp[t] = 0;
  dq.push_back(t);
  while (!dq.empty()) {
    int u = dq.front();
    dq.pop_front();
    if (vis[u]) continue;
    vis[u] = true;
    for (auto &v : in[u]) {
      cnt[v]--;
      if (cnt[v] == 0) {
        if (dp[v] > dp[u]) {
          dp[v] = dp[u];
          dq.push_front(v);
        }
      } else {
        if (dp[v] > dp[u] + 1) {
          dp[v] = dp[u] + 1;
          dq.push_back(v);
        }
      }
    }
  }
  printf("%d\n", dp[s] == inf ? -1 : dp[s]);
  return 0;
}
