#include <bits/stdc++.h>
using namespace std;
const int inf = 1000000000, max_n = 1000010;
int n, m, k, u, v, x, y, s, t, a, b, ans, dp[max_n], deg[max_n];
bool mark[max_n];
vector<int> g[max_n];
deque<int> q;
int main() {
  cin >> n >> m;
  while (m--) {
    cin >> u >> v;
    deg[u]++;
    g[v].push_back(u);
  }
  cin >> s >> t;
  memset(dp, 63, sizeof(dp));
  dp[t] = 0;
  q.push_back(t);
  while (q.size()) {
    int v = q.front();
    q.pop_front();
    if (mark[v]) {
      continue;
    }
    mark[v] = 1;
    for (int x : g[v]) {
      deg[x]--;
      if (deg[x]) {
        if (dp[v] + 1 < dp[x]) {
          dp[x] = dp[v] + 1;
          q.push_back(x);
        }
      } else if (dp[v] < dp[x]) {
        dp[x] = dp[v];
        q.push_front(x);
      }
    }
  }
  if (dp[s] > inf) {
    dp[s] = -1;
  }
  cout << dp[s] << endl;
  return 0;
}
