#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000005;
priority_queue<pair<int, int> > F;
int N, M, xc, yc, S, T;
int dp[maxn], outp[maxn];
vector<int> f[maxn];
int main() {
  scanf("%d %d", &N, &M);
  for (int i = 1; i <= M; i++) {
    scanf("%d %d", &xc, &yc);
    f[yc].push_back(xc);
    ++outp[xc];
  }
  memset(dp, 127, sizeof(dp));
  scanf("%d %d", &S, &T);
  dp[T] = 0;
  F.push(make_pair(-dp[T], T));
  while (!F.empty()) {
    pair<int, int> cc = F.top();
    F.pop();
    if (dp[cc.second] != -cc.first) continue;
    for (int i = 0; i < f[cc.second].size(); i++) {
      int cs = f[cc.second][i];
      --outp[cs];
      if (outp[cs] == 0) {
        if (dp[cc.second] < dp[cs]) {
          dp[cs] = dp[cc.second];
          F.push(make_pair(-dp[cs], cs));
        }
      } else {
        if (dp[cc.second] + 1 < dp[cs]) {
          dp[cs] = dp[cc.second] + 1;
          F.push(make_pair(-dp[cs], cs));
        }
      }
    }
  }
  if (dp[S] == 2139062143) dp[S] = -1;
  cout << dp[S] << endl;
  return 0;
}
