#include <bits/stdc++.h>
using namespace std;
int N, M, S, T, U, V;
vector<int> Edges[1111111];
deque<int> Q;
bool Vis[1111111];
int D[1111111], Ans[1111111];
int BFS() {
  Ans[T] = 0;
  Q.push_back(T);
  Vis[T] = true;
  while (!Q.empty()) {
    U = Q.front();
    if (U == S || Ans[S] == Ans[U]) return Ans[S];
    Q.pop_front();
    for (int n = 0; n < Edges[U].size(); ++n) {
      V = Edges[U][n];
      if (--D[V]) {
        if (Ans[V] > Ans[U] + 1) {
          Ans[V] = Ans[U] + 1;
          if (!Vis[V]) {
            Q.push_back(V);
            Vis[V] = true;
          }
        }
      } else {
        if (Ans[V] > Ans[U]) {
          Ans[V] = Ans[U];
          if (!Vis[V]) {
            Q.push_front(V);
            Vis[V] = true;
          }
        }
      }
    }
  }
  return -1;
}
int main() {
  cin >> N >> M;
  while (M--) {
    cin >> U >> V;
    Edges[V].push_back(U);
    ++D[U];
  }
  cin >> S >> T;
  fill(Ans + 1, Ans + N + 1, 1111111111);
  cout << BFS();
  return 0;
}
