#include <bits/stdc++.h>
using namespace std;
const int MAX = 1000010;
const int INF = 0x3F3F3F3F;
template <class T = int>
T get_data() {
  T ret = 0;
  char c;
  while (true) {
    c = getchar();
    if (c >= '0' && c <= '9') {
      break;
    }
  }
  while (true) {
    ret = ret * 10 + c - '0';
    c = getchar();
    if (c < '0' || c > '9') {
      break;
    }
  }
  return ret;
}
int n, m;
int source, sink;
vector<int> rev_graph[MAX];
int dis[MAX];
vector<int> graph[MAX];
bool in_deque[MAX];
void spfa() {
  memset(dis, -1, sizeof(dis));
  dis[sink] = 0;
  deque<int> q;
  for (__typeof((rev_graph[sink]).begin()) it = (rev_graph[sink]).begin();
       it != (rev_graph[sink]).end(); it++) {
    q.push_back(*it);
    in_deque[*it] = true;
  }
  while (!q.empty()) {
    int u = q.front();
    q.pop_front();
    bool all_vis = true;
    int max_u = 0;
    for (__typeof((graph[u]).begin()) it = (graph[u]).begin();
         it != (graph[u]).end(); it++) {
      if (dis[*it] != -1) {
        max_u = max(max_u, dis[*it]);
      } else {
        all_vis = false;
      }
    }
    bool dis_changed = false;
    if (all_vis && (dis[u] == -1 || max_u < dis[u])) {
      dis[u] = max_u;
      dis_changed = true;
    }
    int min_u = INF;
    for (__typeof((graph[u]).begin()) it = (graph[u]).begin();
         it != (graph[u]).end(); it++) {
      if (dis[*it] != -1 && dis[*it] < min_u) {
        min_u = dis[*it];
      }
    }
    if (min_u != INF && (dis[u] == -1 || min_u + 1 < dis[u])) {
      dis[u] = min_u + 1;
      dis_changed = true;
    }
    if (dis_changed) {
      for (__typeof((rev_graph[u]).begin()) it = (rev_graph[u]).begin();
           it != (rev_graph[u]).end(); it++) {
        int v = *it;
        if (!in_deque[v]) {
          in_deque[v] = true;
          if (!q.empty()) {
            if (dis[v] > dis[q.front()]) {
              q.push_back(v);
            } else {
              q.push_front(v);
            }
          } else {
            q.push_back(v);
          }
        }
      }
    }
    in_deque[u] = false;
  }
}
int main() {
  n = get_data();
  m = get_data();
  for (int i = 0; i < m; ++i) {
    int x = get_data();
    int y = get_data();
    graph[x].push_back(y);
    rev_graph[y].push_back(x);
  }
  source = get_data();
  sink = get_data();
  spfa();
  printf("%d\n", dis[source]);
  return 0;
}
