#include <bits/stdc++.h>
using namespace std;
set<int> q, temp;
vector<int> adj[1000010];
int ans[1000010], deg[1000010];
int n, m, s, t, cnt;
int main() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    adj[b].push_back(a);
    deg[a]++;
  }
  cin >> s >> t;
  memset(ans, -1, sizeof ans);
  q.insert(t);
  ans[t] = 0;
  while (((int)((q).size())) + ((int)((temp).size())) > 0) {
    if (((int)((q).size())) == 0) {
      q = temp;
      temp.clear();
      cnt++;
    }
    int v = *(q.begin());
    q.erase(v);
    deg[v] = 0;
    ans[v] = cnt;
    if (v == s) break;
    for (int i = 0; i < ((int)((adj[v]).size())); i++) {
      if (deg[adj[v][i]] > 0) {
        deg[adj[v][i]]--;
        if (deg[adj[v][i]] == 0) {
          q.insert(adj[v][i]);
          temp.erase(adj[v][i]);
        } else
          temp.insert(adj[v][i]);
      }
    }
  }
  cout << ans[s] << endl;
  return 0;
}
