#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 3;
const int N = 1e6 + 3;
int n, m;
int s, t;
vector<int> v[2][N];
int ans[N];
set<pair<int, int> > check;
int tartib(int a) {
  bool t = false;
  int mii = 1e9 + 10, maa = -1;
  for (int i = 0; i < v[1][a].size(); ++i) {
    if (ans[v[1][a][i]] == INF) {
      t = true;
      continue;
    }
    mii = min(mii, ans[v[1][a][i]]);
    maa = max(maa, ans[v[1][a][i]]);
  }
  if (t) return mii + 1;
  return min(mii + 1, maa);
}
void dijkstra() {
  check.insert(make_pair(0, s));
  ans[s] = 0;
  int now, kid;
  int help;
  while (check.size()) {
    now = check.begin()->second;
    check.erase(check.begin());
    for (int i = 0; i < v[0][now].size(); ++i) {
      kid = v[0][now][i];
      if (ans[kid] != INF) continue;
      ans[kid] = tartib(kid);
      check.insert(make_pair(ans[kid], kid));
    }
  }
}
int main() {
  for (int i = 0; i < N; ++i) ans[i] = INF;
  cin >> n >> m;
  int help1, help2;
  for (int i = 0; i < m; ++i) {
    scanf("%d%d", &help1, &help2);
    v[1][help1].push_back(help2);
    v[0][help2].push_back(help1);
  }
  cin >> s >> t;
  swap(s, t);
  dijkstra();
  if (ans[t] == INF) return cout << -1, 0;
  cout << ans[t];
}
