#include <bits/stdc++.h>
using namespace std;
const long long N = 1e6 + 5, inf = 1e9 + 5;
int n;
int m;
int x, y;
vector<int> adj[N];
vector<int> adj2[N];
int dp[N];
set<pair<long long, long long> > st;
int s;
int t;
int mark[N];
int cnt[N];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> x >> y;
    x--;
    y--;
    adj[x].push_back(y);
    adj2[y].push_back(x);
  }
  cin >> s >> t;
  s--;
  t--;
  for (int i = 0; i < n; i++) {
    dp[i] = inf;
  }
  st.insert({0, t});
  dp[t] = 0;
  while (st.size()) {
    auto u = *st.begin();
    st.erase(u);
    if (mark[u.second]) continue;
    mark[u.second] = 1;
    for (auto v : adj2[u.second]) {
      cnt[v]++;
      int mi = u.first;
      int ma = inf;
      if (cnt[v] == adj[v].size()) ma = mi;
      if (min(mi + 1, ma) < dp[v]) {
        st.erase({dp[v], v});
        dp[v] = min(mi + 1, ma);
        st.insert({dp[v], v});
      }
    }
  }
  cout << (dp[s] >= inf ? -1 : dp[s]);
  return 0;
}
