#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
const long long mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
int n, m;
int s, t;
vector<int> g[N], rg[N];
int d[N];
bool vis[N];
void spfa() {
  memset(d, 0x3f, sizeof(d));
  vis[t] = true;
  queue<int> q;
  d[t] = 0;
  q.push(t);
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    vis[u] = false;
    for (auto v : rg[u]) {
      if (d[v] > d[u] + 1) {
        d[v] = d[u] + 1;
        if (!vis[v]) {
          q.push(v);
          vis[v] = true;
        }
      }
    }
    int mx = 0;
    for (auto v : g[u]) {
      mx = max(mx, d[v]);
    }
    if (d[u] > mx) {
      d[u] = mx;
      q.push(u);
      vis[u] = true;
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  memset(d, 0x3f, sizeof(d));
  cin >> n >> m;
  int u, v;
  for (int i = (1); i < (m + 1); i++) {
    cin >> u >> v;
    g[u].push_back(v);
    rg[v].push_back(u);
  }
  cin >> s >> t;
  spfa();
  if (d[s] == inf) d[s] = -1;
  cout << d[s] << endl;
  return 0;
}
