#include <bits/stdc++.h>
using namespace std;
const int max_n = 1000111, inf = 1e9 + 100;
vector<int> rv[max_n];
int out[max_n];
int cnt[max_n];
int d[max_n];
bool vis[max_n];
int main() {
  int n, m;
  int s, t;
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    int from, to;
    scanf("%d %d", &from, &to);
    --from, --to;
    rv[to].push_back(from);
    out[from]++;
  }
  cin >> s >> t;
  --s, --t;
  for (int i = 0; i < n; ++i) {
    d[i] = inf;
  }
  d[t] = 0;
  deque<int> dq;
  dq.push_back(t);
  while (!dq.empty()) {
    int cur = dq.front();
    dq.pop_front();
    if (vis[cur]) {
      continue;
    }
    vis[cur] = 1;
    for (int i = 0; i < rv[cur].size(); ++i) {
      int to = rv[cur][i];
      if (vis[to] || d[to] == d[cur]) {
        continue;
      }
      d[to] = d[cur] + 1;
      dq.push_back(to);
      cnt[to]++;
      if (cnt[to] == out[to]) {
        d[to] = d[cur];
        dq.push_front(to);
      }
    }
  }
  if (d[s] == inf) {
    cout << -1 << endl;
    return 0;
  }
  cout << d[s] << endl;
  return 0;
}
