#include <bits/stdc++.h>
using namespace std;
const int maxx = 1e6 + 7;
bool mark[maxx];
int dist[maxx], vuroodi[maxx];
deque<int> dq;
vector<int> adj[maxx];
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    adj[v].push_back(u);
    vuroodi[u]++;
  }
  int s, t;
  cin >> s >> t;
  s--;
  t--;
  memset(dist, 63, sizeof dist);
  dq.push_back(t);
  dist[t] = 0;
  while (!dq.empty()) {
    int v = dq.front();
    dq.pop_front();
    if (mark[v]) continue;
    mark[v] = true;
    for (int i = 0; i < (int)adj[v].size(); i++) {
      int u = adj[v][i];
      vuroodi[u]--;
      if (vuroodi[u] == 0 && dist[u] > dist[v]) {
        dist[u] = dist[v];
        dq.push_front(u);
      }
      if (vuroodi[u] > 0 && dist[u] > dist[v] + 1) {
        dist[u] = dist[v] + 1;
        dq.push_back(u);
      }
    }
  }
  if (dist[s] > maxx)
    cout << "-1"
         << "\n";
  else
    cout << dist[s] << "\n";
}
