#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1000000 + 10;
vector<int> E[MAX_N];
int n, m, q[MAX_N + MAX_N], vis[MAX_N], d[MAX_N], out[MAX_N];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    E[b].push_back(a);
    out[a]++;
  }
  int s, t;
  scanf("%d%d", &s, &t);
  int qh = MAX_N, qt = MAX_N;
  memset(d, -1, sizeof(d));
  q[qt++] = t;
  d[t] = 0;
  while (qh < qt) {
    int x = q[qh++];
    if (x == s) break;
    if (vis[x]) continue;
    vis[x] = 1;
    for (int i = 0; i < E[x].size(); i++) {
      int y = E[x][i];
      --out[y];
      if (out[y] == 0) {
        if (d[x] < d[y] || d[y] == -1) {
          d[y] = d[x];
          q[--qh] = y;
        }
      } else if (d[y] == -1) {
        d[y] = d[x] + 1;
        q[qt++] = y;
      }
    }
  }
  printf("%d\n", d[s]);
  return 0;
}
