#include <bits/stdc++.h>
using namespace std;
const int RLEN = 1 << 18 | 1;
inline char nc() {
  static char ibuf[RLEN], *ib, *ob;
  (ib == ob) && (ob = (ib = ibuf) + fread(ibuf, 1, RLEN, stdin));
  return (ib == ob) ? -1 : *ib++;
}
inline int rd() {
  char ch = nc();
  int i = 0, f = 1;
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = nc();
  }
  while (isdigit(ch)) {
    i = (i << 1) + (i << 3) + ch - '0';
    ch = nc();
  }
  return i * f;
}
const int N = 1e6 + 50;
int n, m, f[N], deg[N], vis[N];
deque<int> q;
vector<int> edge[N];
int main() {
  n = rd(), m = rd();
  for (int i = 1; i <= m; i++) {
    int x = rd(), y = rd();
    edge[y].push_back(x);
    ++deg[x];
  }
  memset(f, -1, sizeof(f));
  int st = rd(), ed = rd();
  f[ed] = 0;
  q.push_back(ed);
  while (!q.empty()) {
    int u = q.front();
    q.pop_front();
    if (vis[u]) continue;
    vis[u] = 1;
    if (u == st) break;
    for (auto v : edge[u]) {
      if (!--deg[v]) {
        if (f[u] < f[v] || f[v] == -1) {
          f[v] = f[u];
          q.push_front(v);
        }
      } else if (f[v] == -1) {
        f[v] = f[u] + 1;
        q.push_back(v);
      }
    }
  }
  cout << f[st];
}
