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