#include <bits/stdc++.h>
using namespace std;
int sig(double x) { return abs(x) < 1e-9 ? 0 : (x > 0 ? 1 : -1); }
int n, m, k, q;
list<int> Q;
int dp[1000020];
int out[1000020];
vector<int> adj[1000020];
bool done[1000020];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    adj[y].push_back(x);
    out[x]++;
  }
  fill(dp, dp + 1000020, INT32_MAX);
  int s, t;
  scanf("%d%d", &s, &t);
  dp[t] = 0;
  Q.push_back(t);
  while (!Q.empty()) {
    int u = Q.front();
    Q.pop_front();
    if (u == s) break;
    if (done[u]) continue;
    done[u] = true;
    for (int nxt : adj[u]) {
      out[nxt]--;
      if (out[nxt] == 0) {
        if (dp[nxt] > dp[u]) dp[nxt] = dp[u], Q.push_front(nxt);
      } else {
        if (dp[nxt] > dp[u] + 1) dp[nxt] = dp[u] + 1, Q.push_back(nxt);
      }
    }
  }
  if (dp[s] != INT32_MAX)
    cout << dp[s];
  else
    cout << -1;
  return 0;
};
