#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> adj[n], in[n];
  int ot[n];
  for (int i = 0; i < n; i++) ot[i] = 0;
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    adj[x].push_back(y);
    in[y].push_back(x);
    ot[x]++;
  }
  int vis[n];
  for (int i = 0; i < n; i++) {
    vis[i] = 0;
  }
  int st, en;
  cin >> st >> en;
  st--;
  en--;
  deque<int> q;
  int dp[n];
  for (int i = 0; i < n; i++) dp[i] = 10000000;
  dp[en] = 0;
  q.push_back(en);
  while (!q.empty()) {
    int u = q.front();
    q.pop_front();
    if (vis[u] == 1) continue;
    vis[u] = 1;
    for (int i = 0; i < in[u].size(); i++) {
      int v = in[u][i];
      ot[v]--;
      if (ot[v] == 0) {
        if (dp[v] > dp[u]) {
          dp[v] = dp[u];
          q.push_front(v);
        }
      } else {
        if (dp[v] > dp[u] + 1) {
          dp[v] = dp[u] + 1;
          q.push_back(v);
        }
      }
    }
  }
  if (dp[st] != 10000000)
    cout << dp[st];
  else
    cout << -1;
  return 0;
}
