#include <bits/stdc++.h>
using namespace std;
vector<long long int> g[1000001], gt[1000001];
long long int dist[1000001], out[1000001], dp[1000001], vis[1000001],
    q[4000004];
int main() {
  long long int n, m, i, j, s, t, u, v;
  scanf("%lld %lld", &n, &m);
  while (m--) {
    scanf("%lld %lld", &u, &v);
    g[u].push_back(v);
    gt[v].push_back(u);
    out[u]++;
  }
  scanf("%lld %lld", &s, &t);
  for (i = 1; i <= n; i++) {
    dp[i] = -1;
  }
  dp[t] = 0;
  q[2000002] = t;
  long long int fi = 2000002;
  long long int fr = fi + 1;
  while (fi < fr) {
    long long int tmp = q[fi++];
    if (tmp == s) {
      break;
    }
    if (vis[tmp]) continue;
    vis[tmp] = 1;
    for (auto ch : gt[tmp]) {
      out[ch]--;
      if (out[ch] == 0) {
        if (dp[ch] > dp[tmp] || dp[ch] == -1) {
          dp[ch] = dp[tmp];
          q[--fi] = (ch);
        }
      } else if (dp[ch] == -1) {
        dp[ch] = dp[tmp] + 1;
        q[fr++] = (ch);
      }
    }
  }
  if (dp[s] == 1000000000000000) {
    cout << -1 << endl;
  } else {
    cout << dp[s] << endl;
  }
}
