#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 5;
int N, M, s, t;
vector<int> adj[maxn];
int out[maxn];
int dist[maxn];
bool vis[maxn];
signed main(void) {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> N >> M;
  while (M--) {
    int u, v;
    cin >> u >> v;
    adj[v].emplace_back(u);
    out[u]++;
  }
  cin >> s >> t;
  deque<int> dq;
  memset(dist, -1, sizeof dist);
  dist[t] = 0;
  dq.push_back(t);
  while (dq.size()) {
    int u = dq.front();
    dq.pop_front();
    if (u == s) break;
    if (vis[u]) continue;
    vis[u] = true;
    for (int v : adj[u]) {
      out[v]--;
      if (out[v] == 0) {
        if (dist[v] == -1 || dist[v] > dist[u]) {
          dist[v] = dist[u];
          dq.push_front(v);
        }
      } else {
        if (dist[v] == -1 || dist[v] > dist[u] + 1) {
          dist[v] = dist[u] + 1;
          dq.push_back(v);
        }
      }
    }
  }
  cout << dist[s];
}
