#include <bits/stdc++.h>
using namespace std;
int V, E, S, T;
vector<int> graph[1000010];
int indeg[1000010];
deque<pair<int, int> > q;
int dist[1000010];
int main(void) {
  int i;
  cin >> V >> E;
  for ((i) = 0; (i) < (int)(E); (i)++) {
    int a, b;
    scanf("%d%d", &a, &b);
    a--;
    b--;
    graph[b].push_back(a);
    indeg[a]++;
  }
  cin >> T >> S;
  T--;
  S--;
  for ((i) = 0; (i) < (int)(V); (i)++) dist[i] = (1 << 29);
  q.push_back(make_pair(S, 0));
  while (!q.empty()) {
    int x = q[0].first;
    int d = q[0].second;
    q.pop_front();
    if (d >= dist[x]) continue;
    dist[x] = d;
    for ((i) = 0; (i) < (int)(graph[x].size()); (i)++) {
      int y = graph[x][i];
      indeg[y]--;
      if (indeg[y] == 0) q.push_front(make_pair(y, d));
    }
    for ((i) = 0; (i) < (int)(graph[x].size()); (i)++) {
      int y = graph[x][i];
      q.push_back(make_pair(y, d + 1));
    }
  }
  int ans = dist[T];
  if (ans == (1 << 29)) ans = -1;
  cout << ans << endl;
  return 0;
}
