#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target( \
    "avx,avx2,fma,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
long long MOD = 1e9 + 7;
const int N = 1100000;
vector<long long> gr[N];
long long s, t;
long long ans[N];
long long st[N];
long long used[N];
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0),
      cout << fixed << setprecision(20);
  long long n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    long long u, v;
    cin >> u >> v;
    u--, v--;
    gr[v].push_back(u);
    st[u]++;
  }
  cin >> s >> t;
  s--, t--;
  deque<long long> q;
  fill(ans, ans + N, MOD);
  st[t] = 0;
  ans[t] = 0;
  used[t] = 1;
  q.push_back(t);
  while (q.size()) {
    long long v = q.front();
    q.pop_front();
    for (auto i : gr[v]) {
      st[i]--;
      if (st[i] == 0) {
        ans[i] = min(ans[i], ans[v]);
        if (ans[i] == ans[v]) {
          if (!used[i]) {
            used[i] = 1;
            q.push_front(i);
          }
        }
      } else {
        ans[i] = min(ans[i], ans[v] + 1);
        if (ans[i] == ans[v] + 1) {
          if (!used[i]) {
            used[i] = 1;
            q.push_back(i);
          }
        }
      }
    }
  }
  if (ans[s] == MOD) {
    cout << -1;
    return 0;
  }
  cout << ans[s];
}
