#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int N = 1001000;
deque<int> q;
int n, m, S, T, h[N], t[N], e[N], cnt, d[N], v[N], f[N];
void add(int x, int y) {
  t[++cnt] = h[x];
  e[cnt] = y;
  h[x] = cnt;
}
int main() {
  memset(f, 0x3f, sizeof f);
  memset(h, -1, sizeof h);
  scanf("%d%d", &n, &m);
  for (int i = 1, x, y; i <= m; i++) scanf("%d%d", &x, &y), add(y, x), d[x]++;
  scanf("%d%d", &S, &T);
  f[T] = 0;
  q.push_back(T);
  while (!q.empty()) {
    int x = q.front();
    q.pop_front();
    if (v[x]) continue;
    v[x] = 1;
    for (int i = h[x]; ~i; i = t[i]) {
      int u = e[i];
      d[u]--;
      if (d[u]) {
        if (f[u] > f[x] + 1) {
          f[u] = f[x] + 1;
          q.push_back(u);
        }
      } else {
        if (f[u] > f[x]) {
          f[u] = f[x];
          q.push_front(u);
        }
      }
    }
  }
  printf("%d", f[S] != INF ? f[S] : -1);
  return 0;
}
