#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<int> *e;
int s, t;
vector<int> *eRev;
const int inf = 1000000000;
int solve(void) {
  int *result = new int[n + 1];
  for (int i = 1; i <= n; i++) result[i] = inf;
  int *expNeig = new int[n + 1];
  for (int i = 1; i <= n; i++) expNeig[i] = 0;
  result[t] = 0;
  deque<int> vert;
  int seed = s;
  vert.push_front(t);
  while (!vert.empty()) {
    seed = vert.front();
    for (int i = 0; i < e[seed].size(); i++) expNeig[e[seed][i]]++;
    vert.pop_front();
    for (int i = 0; i < e[seed].size(); i++) {
      int nova = e[seed][i];
      if (eRev[nova].size() == 1) {
        result[nova] = result[seed];
        vert.push_front(nova);
      } else {
        if (expNeig[nova] != eRev[nova].size()) {
          if (result[nova] > result[seed] + 1) {
            result[nova] = result[seed] + 1;
            vert.push_back(nova);
          }
        } else {
          bool yes = true;
          for (int j = 0; j < eRev[nova].size(); j++)
            if (result[eRev[nova][j]] >= result[nova]) yes = false;
          if (yes) {
            result[nova]--;
            vert.push_front(nova);
          }
        }
      }
    }
  }
  int temp = result[s];
  delete[] result;
  return temp;
}
int main() {
  cin >> n >> m;
  e = new vector<int>[n + 1];
  eRev = new vector<int>[n + 1];
  int u, v;
  for (int i = 0; i < m; i++) {
    cin >> u >> v;
    e[v].push_back(u);
    eRev[u].push_back(v);
  }
  cin >> s >> t;
  int temp = solve();
  if (temp >= inf)
    cout << -1;
  else
    cout << temp;
  delete[] e, eRev;
  return 0;
}
