#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e6 + 10, INF = 0x3f3f3f3f;
deque<int> q;
struct edge {
  int nxt, to;
} e[MAXN << 2];
int n, m, x, y, s, t, dist[MAXN], out[MAXN], head[MAXN], vis[MAXN], tot, res;
void add(int x, int y) {
  e[++tot] = (edge){head[x], y};
  head[x] = tot;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) scanf("%d%d", &x, &y), add(y, x), out[x]++;
  scanf("%d%d", &s, &t);
  memset(dist, 0x3f, sizeof(dist));
  q.push_back(t);
  dist[t] = 0;
  while (!q.empty()) {
    int v = q.front();
    q.pop_front();
    if (vis[v]) continue;
    vis[v] = 1;
    for (int i = head[v]; i; i = e[i].nxt) {
      int u = e[i].to;
      out[u]--;
      if (!out[u] && dist[u] > dist[v])
        dist[u] = dist[v], q.push_front(u);
      else if (out[u] && dist[u] > dist[v] + 1)
        dist[u] = dist[v] + 1, q.push_back(u);
    }
  }
  printf("%d", dist[s] == INF ? -1 : dist[s]);
  return 0;
}
