#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000 * 1000 + 321;
int n, m, s, t, deg[maxn], dp[maxn], cnt;
vector<int> adj[maxn];
bool mark[maxn];
queue<int> path;
vector<int> active;
void bfs() {
  while (!path.empty()) {
    int v = path.front();
    dp[v] = cnt;
    active.push_back(v);
    path.pop();
    for (int i = 0; i < adj[v].size(); i++) {
      int u = adj[v][i];
      deg[u]--;
      if (!deg[u] && !mark[u]) path.push(u), mark[u] = true;
    }
  }
}
void solve() {
  fill(dp, dp + n, -1);
  dp[t] = 0;
  path.push(t);
  mark[t] = true;
  bfs();
  while (!active.empty()) {
    cnt++;
    for (auto &v : active)
      for (int i = 0; i < adj[v].size(); i++) {
        int u = adj[v][i];
        if (!mark[u]) {
          path.push(u);
          mark[u] = true;
        }
      }
    active.clear();
    bfs();
  }
}
int main() {
  cin >> n >> m;
  for (int i = 0, a, b; i < m; i++) {
    cin >> a >> b;
    a--, b--;
    adj[b].push_back(a);
    deg[a]++;
  }
  cin >> s >> t;
  s--, t--;
  solve();
  cout << dp[s];
}
