#include <bits/stdc++.h>
const int oo = 0x3f3f3f3f;
template <typename T>
inline bool chkmax(T &a, T b) {
  return a < b ? a = b, true : false;
}
template <typename T>
inline bool chkmin(T &a, T b) {
  return a > b ? a = b, true : false;
}
std::string procStatus() {
  std::ifstream t("/proc/self/status");
  return std::string(std::istreambuf_iterator<char>(t),
                     std::istreambuf_iterator<char>());
}
template <typename T>
T read(T &first) {
  int f = 1;
  char ch = getchar_unlocked();
  for (; !isdigit(ch); ch = getchar_unlocked())
    if (ch == '-') f = -1;
  for (first = 0; isdigit(ch); ch = getchar_unlocked())
    first = 10 * first + ch - '0';
  return first *= f;
}
template <typename T>
void write(T first) {
  if (first == 0) {
    putchar_unlocked('0');
    return;
  }
  if (first < 0) {
    putchar_unlocked('-');
    first = -first;
  }
  static char s[20];
  int top = 0;
  for (; first; first /= 10) s[++top] = first % 10 + '0';
  while (top) putchar_unlocked(s[top--]);
}
const int MAXN = 1e6 + 5, MAXM = 1e6 + 5;
struct Edge {
  int v, next;
  Edge() {}
  Edge(int v0, int next0) : v(v0), next(next0) {}
};
int N, M, S, T;
int tote, head[MAXN];
Edge edge[MAXM];
int indeg[MAXN];
inline void addEdge(int u, int v) {
  edge[++tote] = Edge(v, head[u]);
  head[u] = tote;
}
void input() {
  read(N);
  read(M);
  for (int i = 1; i <= M; ++i) {
    int u, v;
    read(u);
    read(v);
    addEdge(v, u);
    ++indeg[u];
  }
  read(S);
  read(T);
}
void solve() {
  static int dp[MAXN];
  static int q0[MAXN * 4 + 5];
  static bool vis[MAXN];
  int front = 0, rear = 0;
  int *q = q0 + N + 1;
  memset(dp, +oo, sizeof(dp));
  dp[T] = 0;
  q[rear++] = T;
  while (front != rear) {
    int u = q[front++];
    if (vis[u]) continue;
    vis[u] = true;
    for (int i = head[u]; i; i = edge[i].next) {
      int v = edge[i].v;
      if (--indeg[v] == 0) {
        if (chkmin(dp[v], dp[u])) q[--front] = v;
      } else if (chkmin(dp[v], dp[u] + 1))
        q[rear++] = v;
    }
  }
  printf("%d\n", dp[S] == +oo ? -1 : dp[S]);
}
int main() {
  input();
  solve();
  return 0;
}
