#include <bits/stdc++.h>
using namespace std;
void read(int& x) {
  bool fu = 0;
  char c;
  for (c = getchar(); c <= 32; c = getchar())
    ;
  if (c == '-') fu = 1, c = getchar();
  for (x = 0; c > 32; c = getchar()) x = x * 10 + c - '0';
  if (fu) x = -x;
};
char getc() {
  char c;
  for (c = getchar(); c <= 32; c = getchar())
    ;
  return c;
}
const int N = 1000010;
const int M = 1000010;
int n, m, i, j, k, l, x, y, S, T, edge, fir[N], last[N], e[M], b[M];
void clear() {
  edge = 0;
  memset(fir, -1, sizeof(fir));
  memset(b, -1, sizeof(b));
}
void add(int x, int y) {
  e[edge] = y;
  if (fir[x] == -1)
    fir[x] = edge;
  else
    b[last[x]] = edge;
  last[x] = edge++;
}
deque<int> Q;
int p[N], d[N];
bool v[N];
int main() {
  clear();
  read(n);
  read(m);
  for (i = 1; i <= m; i++) read(x), read(y), add(y, x), d[x]++;
  read(S);
  read(T);
  memset(p, 127, sizeof(p));
  Q.push_front(T);
  p[T] = 0;
  while (!Q.empty()) {
    i = Q.front();
    Q.pop_front();
    if (v[i]) continue;
    v[i] = 1;
    for (k = fir[i]; k >= 0; k = b[k]) {
      if (--d[e[k]] == 0) {
        if (p[i] < p[e[k]]) {
          p[e[k]] = p[i];
          Q.push_front(e[k]);
        }
      } else {
        if (p[e[k]] == p[0]) {
          p[e[k]] = p[i] + 1;
          Q.push_back(e[k]);
        }
      }
    }
  }
  if (p[S] == p[0])
    printf("-1\n");
  else
    printf("%d\n", p[S]);
  scanf("\n");
  return 0;
}
