#include <bits/stdc++.h>
using namespace std;
int n, m;
int d[1000001];
vector<int> gr[1000001];
int deg[1000001];
int x, y;
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; ++i) {
    int v1, v2;
    scanf("%d%d", &v1, &v2);
    --v1, --v2;
    gr[v2].push_back(v1);
    ++deg[v1];
  }
  scanf("%d%d", &x, &y);
  --x, --y;
  for (int i = 0; i < n; ++i) d[i] = 100000000;
  deque<pair<int, int> > q;
  q.push_back(make_pair(y, 0));
  while (!q.empty()) {
    int v = q.front().first;
    int dist = q.front().second;
    q.pop_front();
    if (dist >= d[v]) continue;
    d[v] = dist;
    for (int i = gr[v].size() - 1; i >= 0; --i) {
      int v2 = gr[v][i];
      --deg[v2];
      if (!deg[v2]) q.push_front(make_pair(v2, dist));
      q.push_back(make_pair(v2, dist + 1));
    }
  }
  printf("%d\n", d[x] == 100000000 ? -1 : d[x]);
  return 0;
}
