#include <bits/stdc++.h>
using namespace std;
bool update;
vector<int> E[2][1001000];
int dist[1000100];
int s, t, n, m;
bool f[1000100];
vector<int> V;
stack<int> S;
void cek(int v) {
  int ret = dist[v];
  int tmp = 0;
  for (int i = 0; i < E[0][v].size(); i++) {
    int w = E[0][v][i];
    tmp = max(tmp, dist[w]);
    if (tmp >= ret) break;
  }
  ret = min(ret, tmp);
  tmp = n + 1;
  for (int i = 0; i < E[0][v].size(); i++) {
    int w = E[0][v][i];
    tmp = min(1 + dist[w], tmp);
  }
  ret = min(ret, tmp);
  for (int i = 0; i < E[1][v].size(); i++) {
    int w = E[1][v][i];
    if (!f[w]) {
      f[w] = 1;
      S.push(w);
    }
  }
  if (ret < dist[v]) {
    dist[v] = ret;
    S.push(v);
    update = 1;
  }
}
void bellman(int s, int t) {
  for (int i = 1; i <= n; i++)
    if (i == t)
      dist[i] = 0;
    else
      dist[i] = n + 1;
  V.clear();
  memset(f, 0, sizeof(f));
  f[t] = 1;
  for (int i = 0; i < E[1][t].size(); i++) {
    int w = E[1][t][i];
    V.push_back(w);
    f[w] = 1;
  }
  do {
    update = 0;
    for (int i = 0; i < V.size(); i++) cek(V[i]);
    V.clear();
    while (!S.empty()) {
      V.push_back(S.top());
      S.pop();
    }
  } while (update);
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    E[0][a].push_back(b);
    E[1][b].push_back(a);
  }
  scanf("%d%d", &s, &t);
  bellman(s, t);
  printf("%d\n", (dist[s] > n) ? -1 : dist[s]);
  return 0;
}
