#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 100;
const int logn = log2(maxn) + 1;
const int mod = 1e9 + 7;
vector<int> adj[maxn];
int n, m, s, t;
int dis[maxn];
int deg[maxn];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  if (fopen("A"
            ".INP",
            "r")) {
    freopen(
        "A"
        ".INP",
        "r", stdin);
    freopen(
        "A"
        ".OUT",
        "w", stdout);
  }
  cin >> n >> m;
  fill_n(dis, maxn, 1e9);
  for (int i = 0; i < m; ++i) {
    int u, v;
    cin >> u >> v;
    adj[v].push_back(u);
    deg[u]++;
  }
  cin >> s >> t;
  deque<int> q;
  dis[t] = 0;
  q.push_back(t);
  while (q.size()) {
    int u = q.front();
    q.pop_front();
    for (auto& c : adj[u]) {
      if (--deg[c] == 0) {
        if (dis[c] > dis[u]) {
          dis[c] = dis[u];
          q.push_front(c);
        }
      } else {
        if (dis[c] > dis[u] + 1) {
          dis[c] = dis[u] + 1;
          q.push_back(c);
        }
      }
    }
    adj[u].clear();
  }
  if (dis[s] > n) dis[s] = -1;
  cout << dis[s];
}
