#include <bits/stdc++.h>
using namespace std;
int n, m, x, y, s, f, dp[1000005], de[1000005];
vector<int> G[1000005], GT[1000005];
deque<int> dq;
bool uz[1000005];
int main() {
  scanf("%d %d", &n, &m);
  while (m--) {
    scanf("%d %d", &x, &y);
    G[x].push_back(y);
    GT[y].push_back(x);
    de[x]++;
  }
  scanf("%d %d", &s, &f);
  for (int i = 1; i <= n; i++) dp[i] = 2000000000;
  dp[f] = 0;
  dq.push_back(f);
  while (!dq.empty()) {
    x = dq.front();
    dq.pop_front();
    while (uz[x] && !dq.empty()) {
      x = dq.front();
      dq.pop_front();
    }
    if (uz[x]) break;
    uz[x] = 1;
    for (auto y : GT[x]) {
      if (--de[y] == 0) {
        if (dp[x] < dp[y]) {
          dp[y] = dp[x];
          dq.push_front(y);
        }
      } else if (dp[x] + 1 < dp[y]) {
        dp[y] = dp[x] + 1;
        dq.push_back(y);
      }
    }
  }
  printf("%d\n", (dp[s] == 2000000000) ? (-1) : dp[s]);
  return 0;
}
