#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 1000 * 1000 + 10;
set<long long> out[MAXN], in[MAXN];
deque<long long> dq;
long long dp[MAXN];
bool mark[MAXN];
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n, m;
  cin >> n >> m;
  for (long long i = 0; i < m; i++) {
    long long u, v;
    cin >> u >> v;
    u--, v--;
    out[u].insert(v);
    in[v].insert(u);
  }
  long long s, t;
  cin >> s >> t;
  s--, t--;
  memset(dp, 63, sizeof dp);
  dq.push_front(t);
  dp[t] = 0;
  while ((long long)dq.size()) {
    long long v = dq.front();
    dq.pop_front();
    if (!mark[v]) {
      mark[v] = true;
      for (long long u : in[v]) {
        if ((long long)out[u].size() == 1) {
          dq.push_front(u);
          (dp[u]) = min((dp[u]), (dp[v]));
        } else {
          dq.push_back(u);
          (dp[u]) = min((dp[u]), (dp[v] + 1));
        }
        out[u].erase(v);
      }
    }
  }
  cout << (dp[s] > 1e15 ? -1 : dp[s]) << endl;
  return 0;
}
