#include <bits/stdc++.h>
using namespace std;
const int inf = ~0U >> 1;
const long long INF = (long long)1e18;
const double pi = acos(-1.0);
template <class T>
inline void read(T &n) {
  char c;
  for (c = getchar(); !(c >= '0' && c <= '9'); c = getchar())
    ;
  n = c - '0';
  for (c = getchar(); c >= '0' && c <= '9'; c = getchar()) n = n * 10 + c - '0';
}
int pw(int base, int n, int mo) {
  if (n == 0) return 1;
  if (n == 1) return base;
  int tmp = pw(base, n >> 1, mo);
  tmp = (long long)tmp * tmp % mo;
  if (n & 1) tmp = (long long)tmp * base % mo;
  return tmp;
}
struct point {
  int x, y;
  point() {}
  point(int _x, int _y) : x(_x), y(_y) {}
};
const int mn = 1200000;
struct edge {
  int y;
  edge *nxt;
  edge(int _y, edge *_nxt) : y(_y), nxt(_nxt) {}
} * head[mn];
void add(int x, int y) { head[x] = new edge(y, head[x]); }
int N, M, x, y, S, T, vis[mn], dp[mn], deq[mn];
deque<int> Q;
int main() {
  read(N);
  read(M);
  for (int i = (1); i <= (M); ++i) {
    read(x), read(y);
    add(y, x), deq[x]++;
  }
  read(S);
  read(T);
  memset(dp, 0x7f, sizeof(dp));
  dp[T] = 0;
  Q.push_back(T);
  vis[T] = 1;
  while (Q.size()) {
    int u = Q.front();
    Q.pop_front();
    for (edge *i = head[u]; i; i = i->nxt) {
      int v = i->y;
      if (!(--deq[v])) {
        if (dp[u] < dp[v]) {
          dp[v] = dp[u];
          if (!vis[v]) vis[v] = 1, Q.push_front(v);
        }
      } else {
        if (dp[u] + 1 < dp[v]) {
          dp[v] = dp[u] + 1;
          if (!vis[v]) vis[v] = 1, Q.push_back(v);
        }
      }
    }
  }
  printf("%d\n", (dp[S] == dp[0]) ? -1 : dp[S]);
  return 0;
}
