#include <bits/stdc++.h>
#pragma warning(disable : 4996)
using namespace std;
int n, m;
int s, e;
vector<int> a[1000005];
vector<int> b[1000005];
int q[1000005];
int qi;
int check[1000005];
int q2[1000005];
int q2i;
int outdeg[1000005];
int main() {
  int i, j, k;
  scanf("%d%d", &n, &m);
  for (i = 0; i < m; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    x--, y--;
    a[x].push_back(y);
    b[y].push_back(x);
  }
  scanf("%d%d", &s, &e);
  s--, e--;
  for (i = 0; i < n; i++) check[i] = -1, outdeg[i] = a[i].size();
  check[e] = 0;
  q[qi++] = e;
  int now;
  for (i = 0;; i++) {
    int flag = 0;
    q2i = 0;
    for (j = 0; j < qi; j++) {
      int size = b[q[j]].size();
      if (check[q[j]] < i) continue;
      for (k = 0; k < size; k++) {
        now = b[q[j]][k];
        if (check[now] >= 0 && check[now] <= i) continue;
        outdeg[now]--;
        if (outdeg[now] == 0) {
          check[now] = i;
          q[qi++] = now;
        } else {
          if (check[now] == -1) {
            check[now] = i + 1;
            q2[q2i++] = now;
          }
        }
      }
    }
    if (q2i == 0) break;
    for (j = 0; j < q2i; j++) q[j] = q2[j];
    qi = q2i;
  }
  printf("%d", check[s]);
  return 0;
}
