#include <bits/stdc++.h>
using namespace std;
const int N = 1000000 + 10;
vector<int> radj[N];
int n, m, dp[N], deg[N];
set<pair<int, int> > dij;
int main() {
  scanf("%d%d", &n, &m);
  int u, v;
  while (m--) {
    scanf("%d%d", &u, &v);
    radj[v].push_back(u);
    deg[u]++;
  }
  int s, t;
  scanf("%d%d", &s, &t);
  memset(dp, 127, sizeof dp);
  dp[t] = 0;
  for (int i = 1; i <= n; i++) dij.insert({dp[i], i});
  while ((int)dij.size()) {
    u = dij.begin()->second;
    dij.erase(dij.begin());
    for (int to : radj[u]) {
      deg[to]--;
      if (!deg[to] && dp[u] < dp[to]) {
        dij.erase({dp[to], to});
        dij.insert({dp[to] = dp[u], to});
      } else if (deg[to] && dp[u] + 1 < dp[to]) {
        dij.erase({dp[to], to});
        dij.insert({dp[to] = dp[u] + 1, to});
      }
    }
  }
  printf("%d\n", dp[s] > n ? -1 : dp[s]);
  return 0;
}
