#include <bits/stdc++.h>
const int N = int(1e6) + 100;
int n, m, source, target;
int dist[N], size[N];
bool visited[N];
std::vector<int> adj[N];
std::deque<int> deque;
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    x--, y--;
    adj[y].push_back(x);
    size[x]++;
  }
  std::fill(dist, dist + n, -1);
  std::fill(visited, visited + n, false);
  scanf("%d%d", &source, &target);
  source--, target--;
  dist[target] = 0;
  deque.push_back(target);
  while (!deque.empty()) {
    int x = deque.front();
    deque.pop_front();
    if (visited[x]) {
      continue;
    }
    visited[x] = true;
    for (int i = 0; i < (int)adj[x].size(); i++) {
      int y = adj[x][i];
      if (size[y]-- == 1) {
        if (dist[y] == -1 || dist[x] < dist[y]) {
          dist[y] = dist[x];
          deque.push_front(y);
        }
      } else if (dist[y] == -1) {
        dist[y] = dist[x] + 1;
        deque.push_back(y);
      }
    }
  }
  printf("%d\n", dist[source]);
}
