#include <bits/stdc++.h>
using namespace std;
int dp[2000000], head[1100000], head2[1100000], len, len2;
struct edge {
  int v, fail;
  edge() {}
  edge(int a, int c) {
    v = a;
    fail = c;
  }
} e[2200000], e2[2200000];
void add(int a, int b) {
  e[len] = edge(b, head[a]);
  head[a] = len++;
}
void Add(int a, int b) {
  e2[len2] = edge(a, head2[b]);
  head2[b] = len2++;
}
int vis[2200000];
queue<int> q;
int main() {
  ios::sync_with_stdio(0);
  memset(head, -1, sizeof(head));
  memset(head2, -1, sizeof(head2));
  int n, m, s, t;
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    int x, y, z;
    cin >> x >> y;
    add(x, y);
    Add(x, y);
  }
  cin >> s >> t;
  for (int i = 1; i <= n + 20; i++) {
    dp[i] = 1147483646;
  }
  vis[t] = 1;
  dp[t] = 0;
  q.push(t);
  while (!q.empty()) {
    int now = q.front();
    q.pop();
    vis[now] = 0;
    for (int i = head2[now]; ~i; i = e2[i].fail) {
      if (dp[e2[i].v] > dp[now] + 1) {
        dp[e2[i].v] = dp[now] + 1;
        if (!vis[e2[i].v]) {
          vis[e2[i].v] = 1;
          q.push(e2[i].v);
        }
      }
    }
    int Max = 0;
    for (int i = head[now]; ~i; i = e[i].fail) {
      Max = max(Max, dp[e[i].v]);
    }
    if (dp[now] > Max) {
      dp[now] = Max;
      if (!vis[now]) {
        vis[now] = 1;
        q.push(now);
      }
    }
  }
  if (dp[s] != 1147483646)
    cout << dp[s] << endl;
  else
    cout << -1 << endl;
  return 0;
}
