#include <bits/stdc++.h>
using namespace std;
const long long MXN = 500 + 10;
const long long MXM = (1LL << 18) + 10;
const long long MX5 = 1e5 + 10;
const long long MX6 = 1e6 + 10;
const long long LOG = 20;
const long long INF = 8e18;
const double eps = 1e-9;
const long long MOD = 1e9 + 7;
long long power(long long a, long long b, long long md) {
  return (!b ? 1
             : (b & 1 ? a * power(a * a % md, b / 2, md) % md
                      : power(a * a % md, b / 2, md) % md));
}
long long bmm(long long a, long long b) {
  return (a % b == 0 ? b : bmm(b, a % b));
}
string base2(long long n) {
  string a = "";
  while (n >= 2) {
    a += (char)(n % 2 + '0');
    n /= 2;
  }
  a += (char)(n + '0');
  reverse((a).begin(), (a).end());
  return a;
}
long long n, m, s, t;
long long dp[MX6], d[MX6];
vector<long long> G[MX6];
set<pair<long long, long long> > st;
bool vis[MX6];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  fill(dp, dp + MX6, INF);
  for (int i = 0; i < m; i++) {
    long long u, v;
    cin >> u >> v;
    G[v].push_back(u);
    d[u]++;
  }
  cin >> s >> t;
  dp[t] = 0;
  st.insert({0, t});
  while (!st.empty()) {
    auto itr = st.begin();
    long long u = itr->second, nw = itr->first;
    st.erase(itr);
    if (vis[u]) continue;
    vis[u] = 1;
    for (auto v : G[u]) {
      if (vis[v]) continue;
      if (st.find({d[v], v}) != st.end()) st.erase({d[v], v});
      d[v]--;
      if (d[v] == 0) {
        dp[v] = min(dp[v], dp[u]);
      } else {
        dp[v] = min(dp[v], dp[u] + 1);
      }
      st.insert({dp[v], v});
    }
  }
  cout << (dp[s] == INF ? -1 : dp[s]);
  return 0;
}
