#include <bits/stdc++.h>
int dis[1048576];
std::vector<int> node[1048576], rnode[1048576];
int main() {
  int n, m, s, t;
  scanf("%d%d", &n, &m);
  while (m--) {
    int u, v;
    scanf("%d%d", &u, &v);
    node[u].push_back(v);
    rnode[v].push_back(u);
  }
  scanf("%d%d", &s, &t);
  memset(dis + 1, (int)0x7f7f7f7f, sizeof(int) * n);
  dis[t] = 0;
  std::priority_queue<std::pair<int, int>, std::vector<std::pair<int, int> >,
                      std::greater<std::pair<int, int> > >
      pq;
  pq.push(std::pair<int, int>(0, t));
  while (!pq.empty()) {
    const int u = pq.top().second, cu = pq.top().first;
    pq.pop();
    if (cu != dis[u]) continue;
    for (auto v : rnode[u]) {
      if (dis[v] <= dis[u]) continue;
      int max = 0, min = dis[v];
      for (auto k : node[v]) {
        max = std::max(max, dis[k]);
        min = std::min(min, dis[k]);
      }
      const int cv = std::min(max, min + 1);
      if (cv < dis[v]) pq.push(std::pair<int, int>(dis[v] = cv, v));
    }
  }
  printf("%d\n", dis[s] == (int)0x7f7f7f7f ? -1 : dis[s]);
  return 0;
}
