#include <bits/stdc++.h>
using namespace std;
template <typename T1, typename T2>
inline void mine(T1 &x, T2 y) {
  if (x > y) x = y;
}
template <typename T1, typename T2>
inline void maxe(T1 &x, T2 y) {
  if (x < y) x = y;
}
ostream &operator<<(ostream &a, const vector<long long> &b) {
  for (auto k : b) cout << k << ' ';
  return a;
}
const long long MOD = 1000000007;
const long long INF = 1000000050;
const long long BIG = (long long)2e18 + 50;
const long long MX = 1000010;
const double EPS = 1e-9;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
long long dp[MX];
vector<long long> gt[MX];
long long pw[MX];
bool used[MX];
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n, m;
  cin >> n >> m;
  fill(dp, dp + n, INF);
  for (long long i = 0; i < m; i++) {
    long long a, b;
    cin >> a >> b;
    --a;
    --b;
    gt[b].push_back(a);
    pw[a]++;
  }
  long long s, t;
  cin >> s >> t;
  --s;
  --t;
  dp[t] = 0;
  deque<long long> q;
  q.push_front(t);
  while (!q.empty()) {
    long long v = q.front();
    q.pop_front();
    if (used[v]) continue;
    used[v] = true;
    for (auto &to : gt[v]) {
      --pw[to];
      if (pw[to] == 0) {
        if (dp[v] < dp[to]) {
          dp[to] = dp[v];
          q.push_front(to);
        }
      } else {
        if (dp[v] + 1 < dp[to]) {
          dp[to] = dp[v] + 1;
          q.push_back(to);
        }
      }
    }
  }
  cout << (dp[s] == INF ? -1 : dp[s]) << '\n';
}
