#include <bits/stdc++.h>
using namespace std;
const int maxm = 1001000;
const int INF = 0x3fffffff;
const int maxn = 1001000;
vector<int> pre[maxn];
int out[maxn];
int dp[maxn];
bool vis[maxn];
deque<int> q;
int bfs(int s, int e) {
  memset(dp, -1, sizeof(dp));
  q.push_back(e);
  dp[e] = 0;
  while (!q.empty()) {
    int u = q.front();
    q.pop_front();
    if (u == s) return dp[s];
    if (vis[u]) continue;
    vis[u] = true;
    for (int i = 0; i < pre[u].size(); i++) {
      int v = pre[u][i];
      if (!(--out[v])) {
        if (dp[u] < dp[v] || dp[v] == -1) {
          dp[v] = dp[u];
          q.push_front(v);
        }
      } else if (dp[v] == -1) {
        dp[v] = dp[u] + 1;
        q.push_back(v);
      }
    }
  }
  return -1;
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  while (m--) {
    int u, v;
    scanf("%d%d", &u, &v);
    pre[v].push_back(u);
    out[u]++;
  }
  int s, e;
  scanf("%d%d", &s, &e);
  printf("%d\n", bfs(s, e));
}
