#include <bits/stdc++.h>
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("O8")
#pragma GCC optimization("unroll-loops")
using namespace std;
const long long int N = 1e6 + 20, mod = 1e9, inf = 4e18, maxm = 2e5 + 20;
const long double eps = 0.0001;
int dp[N];
bool vis[N];
int s, t;
vector<int> adj[N], in[N];
int cnt[N];
void dfs(int v) {
  vis[v] = 1;
  for (int u : adj[v])
    if (!vis[u]) dfs(u);
}
void bfs() {
  deque<int> q;
  q.push_back(t);
  while (!q.empty()) {
    int u = q.front();
    q.pop_front();
    if (vis[u]) continue;
    for (int v : in[u]) {
      cnt[v]++;
      if (dp[v] > dp[u] && cnt[v] == adj[v].size()) {
        q.push_front(v);
        dp[v] = dp[u];
      } else if (dp[v] > dp[u] + 1) {
        dp[v] = dp[u] + 1;
        q.push_back(v);
      }
    }
    vis[u] = 1;
  }
}
int main() {
  ios ::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  memset(dp, 63, sizeof dp);
  int n, m;
  cin >> n >> m;
  for (long long int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    adj[u].push_back(v);
    in[v].push_back(u);
  }
  cin >> s >> t;
  dfs(s);
  if (!vis[t]) {
    cout << -1;
    return 0;
  }
  dp[t] = 0;
  memset(vis, 0, sizeof vis);
  bfs();
  cout << dp[s];
  return 0;
}
