#include <bits/stdc++.h>
using namespace std;
const int maxm = 1000010;
const int maxn = 1000010;
struct EE {
  int to, ne;
} e[maxm];
int head[maxn], L;
int du[maxn];
void adde(int u, int v) {
  du[v]++;
  e[L].ne = head[u];
  e[L].to = v;
  head[u] = L++;
}
int s, t;
int dis[maxn];
int que[2 * maxn];
int same[maxn];
bool vis[maxn];
int n, m;
void bfs() {
  memset(dis, -1, sizeof(dis));
  memset(same, 0, sizeof(same));
  dis[t] = 0;
  int l, r;
  l = r = maxn;
  que[r++] = t;
  while (l < r) {
    int u = que[l++];
    if (vis[u]) continue;
    vis[u] = true;
    for (int i = head[u]; i != -1; i = e[i].ne) {
      int v = e[i].to;
      if (--du[v]) {
        if (dis[v] == -1 || dis[v] > dis[u] + 1) {
          dis[v] = dis[u] + 1;
          que[r++] = v;
        }
      } else {
        if (dis[v] == -1 || dis[v] > dis[u]) {
          dis[v] = dis[u];
          que[--l] = v;
        }
      }
    }
  }
}
int main() {
  while (scanf("%d%d", &n, &m) != EOF) {
    memset(vis, 0, sizeof(vis));
    memset(head, -1, sizeof(head));
    memset(du, 0, sizeof(du));
    L = 0;
    for (int i = 0; i < m; i++) {
      int u, v;
      scanf("%d%d", &u, &v);
      adde(v, u);
    }
    scanf("%d%d", &s, &t);
    bfs();
    printf("%d\n", dis[s]);
  }
}
