#include <bits/stdc++.h>
using namespace std;
const int N = 1000000 + 5;
struct coord {
  int x, y;
};
bool operator<(const coord &l, const coord &r) { return (l.y > r.y); }
priority_queue<coord> qu;
int n, m;
int qa[N], dig[N], mi[N], d[N];
int ma[N];
vector<int> graph[N];
vector<int> graphT[N];
int main() {
  int s, f;
  coord e;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; ++i) {
    scanf("%d%d", &s, &f);
    graphT[s].push_back(f);
    graph[f].push_back(s);
  }
  scanf("%d%d", &s, &f);
  for (int i = 1; i <= n; ++i) {
    qa[i] = 0;
    dig[i] = graphT[i].size();
    mi[i] = -1;
    ma[i] = -1;
    d[i] = -1;
  }
  coord c;
  c.x = f;
  c.y = 0;
  qu.push(c);
  while (!qu.empty()) {
    c = qu.top();
    qu.pop();
    if (d[c.x] != -1) continue;
    d[c.x] = c.y;
    int v = c.x;
    for (unsigned int j = 0; j < graph[v].size(); ++j) {
      int to = graph[v][j];
      if (d[to] == -1) {
        ++qa[to];
        if (mi[to] == -1 || mi[to] > d[v]) mi[to] = d[v];
        if (ma[to] < d[v]) ma[to] = d[v];
        if (qa[to] == dig[to] && ma[to] == mi[to]) {
          e.x = to;
          e.y = mi[to];
          qu.push(e);
        } else {
          e.x = to;
          e.y = d[v] + 1;
          qu.push(e);
        }
      }
    }
  }
  printf("%d\n", d[s]);
  return 0;
}
