#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 7;
int n, m, i, x, y, cost, s, t;
int out[N], dp[N];
bool H[N];
vector<int> V[N];
priority_queue<pair<int, int>, vector<pair<int, int> >,
               greater<pair<int, int> > >
    Q;
int main() {
  scanf("%d %d", &n, &m);
  for (i = 1; i <= m; i++) {
    scanf("%d %d", &x, &y);
    V[y].push_back(x);
    out[x]++;
  }
  scanf("%d %d", &s, &t);
  for (i = 1; i <= n; i++) dp[i] = inf;
  Q.push(make_pair(0, t));
  dp[t] = 0;
  while (!Q.empty()) {
    x = Q.top().second;
    cost = Q.top().first;
    Q.pop();
    if (H[x]) continue;
    H[x] = 1;
    for (i = 0; i < V[x].size(); i++) {
      int u = V[x][i];
      out[u]--;
      if (!out[u] and dp[u] > dp[x]) {
        dp[u] = dp[x];
        Q.push(make_pair(dp[u], u));
      } else if (dp[u] > dp[x] + 1) {
        dp[u] = dp[x] + 1;
        Q.push(make_pair(dp[u], u));
      }
    }
  }
  if (dp[s] < inf)
    cout << dp[s];
  else
    cout << -1;
}
