#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, m, s, t;
  cin >> n >> m;
  vector<vector<int> > g(n + 1);
  vector<bool> vis(n + 1, 0);
  vector<int> indeg(n + 1, 0);
  vector<int> dp(n + 1, -1);
  queue<int> qf, ql;
  while (m--) {
    int a, b;
    cin >> a >> b;
    g[b].push_back(a);
    indeg[a]++;
  }
  cin >> s >> t;
  dp[t] = 0;
  qf.push(t);
  while (!qf.empty() | !ql.empty()) {
    while (!qf.empty()) {
      int v = qf.front();
      qf.pop();
      if (vis[v]) continue;
      vis[v] = 1;
      for (auto to : g[v]) {
        indeg[to]--;
        if (!indeg[to]) {
          if (dp[to] == -1) {
            dp[to] = dp[v];
            qf.push(to);
          } else if (dp[to] > dp[v]) {
            dp[to] = dp[v];
            qf.push(to);
          }
        } else if (dp[to] == -1) {
          dp[to] = dp[v] + 1;
          ql.push(to);
        }
      }
    }
    bool f = 0;
    while (!ql.empty()) {
      int v = ql.front();
      ql.pop();
      if (vis[v]) continue;
      vis[v] = 1;
      for (auto to : g[v]) {
        indeg[to]--;
        if (!indeg[to]) {
          if (dp[to] == -1) {
            dp[to] = dp[v];
            qf.push(to);
            f = 1;
          } else if (dp[to] > dp[v]) {
            dp[to] = dp[v];
            qf.push(to);
            f = 1;
          }
        } else if (dp[to] == -1) {
          dp[to] = dp[v] + 1;
          ql.push(to);
        }
      }
      if (f) break;
    }
  }
  cout << dp[s];
  return 0;
}
