#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e6 + 10;
vector<int> G[MAXN];
int dp[MAXN], out[MAXN];
int que[MAXN * 2];
bool vis[MAXN];
int n, m, s, t;
int main() {
  int u, v;
  scanf("%d %d", &n, &m);
  for (int i = 0; i < m; ++i) {
    scanf("%d %d", &u, &v);
    G[v].push_back(u);
    out[u]++;
  }
  scanf("%d %d", &s, &t);
  memset(dp, -1, sizeof(dp));
  dp[t] = 0;
  int lt = MAXN, rt = MAXN + 1;
  que[lt] = t;
  int cur;
  while (lt < rt) {
    cur = que[lt++];
    if (cur == s) break;
    if (vis[cur]) continue;
    vis[cur] = true;
    for (int i = 0; i < G[cur].size(); ++i) {
      v = G[cur][i];
      if (--out[v] == 0) {
        if (dp[v] > dp[cur] || dp[v] == -1) {
          dp[v] = dp[cur];
          que[--lt] = v;
        }
      } else if (dp[v] == -1) {
        dp[v] = dp[cur] + 1;
        que[rt++] = v;
      }
    }
  }
  printf("%d\n", dp[s]);
  return 0;
}
