#include <bits/stdc++.h>
using namespace std;
const long long linf = 1e18 + 5;
const int mod = (int)1e9 + 7;
const int logN = 17;
const int inf = 1e9;
const int N = 1e6 + 5;
int h[N], s, t, n, m, x, y, in[N], dp[N];
vector<int> v[N];
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d %d", &x, &y);
    v[y].push_back(x);
    in[x]++;
  }
  scanf("%d %d", &s, &t);
  priority_queue<pair<int, int>, vector<pair<int, int> >,
                 greater<pair<int, int> > >
      q;
  for (int i = 1; i <= n; i++) dp[i] = inf;
  q.push(make_pair(0, t));
  while (q.size()) {
    int node = q.top().second;
    int cost = q.top().first;
    q.pop();
    if (h[node]) continue;
    h[node] = 1;
    dp[node] = cost;
    for (__typeof(v[node].begin()) it = v[node].begin(); it != v[node].end();
         it++) {
      if (dp[node] + 1 < dp[*it]) {
        dp[*it] = dp[node] + 1;
        q.push(make_pair(dp[*it], *it));
      }
      if (!--in[*it]) {
        if (dp[*it] > dp[node]) {
          dp[*it] = dp[node];
          q.push(make_pair(dp[node], *it));
        }
      }
    }
  }
  if (dp[s] < inf)
    cout << dp[s] << '\n';
  else
    cout << -1 << '\n';
  return 0;
}
