#include <bits/stdc++.h>
using namespace std;
const int N = 1000005;
inline int IN() {
  char ch;
  (ch = getchar());
  int f = 0, x = 0;
  for (; ((ch) == '\n' || (ch) == '\r' || (ch) == '\t' || (ch) == ' ');
       (ch = getchar()))
    ;
  if (ch == '-') f = 1, (ch = getchar());
  for (; !((ch) == '\n' || (ch) == '\r' || (ch) == '\t' || (ch) == ' ');
       (ch = getchar()))
    x = x * 10 + ch - '0';
  return (f) ? (-x) : (x);
}
int n, m, s, t, f[N];
vector<int> E[N], rev_E[N];
queue<int> Q;
bool In[N];
int Com(int x, int y) {
  if (y == -1) return 1;
  return x < y;
}
int main() {
  n = IN(), m = IN();
  for (int i = (int)1; i <= (int)m; i++) {
    int u = IN(), v = IN();
    E[u].push_back(v);
    rev_E[v].push_back(u);
  }
  memset(f, -1, sizeof f);
  s = IN(), t = IN();
  f[t] = 0;
  for (__typeof(*rev_E[t].begin()) v : rev_E[t]) {
    Q.push(v);
    In[v] = 1;
  }
  while (!Q.empty()) {
    int u = Q.front();
    Q.pop();
    bool flag = 0, all = 1, has = 0;
    In[u] = 0;
    int Min = 2100000000, Max = -Min;
    for (__typeof(*E[u].begin()) v : E[u]) {
      if (f[v] == -1) all = 0;
      if (f[v] != -1) has = 1;
      if (f[v] != -1) {
        Min = min(Min, f[v]);
        Max = max(Max, f[v]);
      }
    }
    ++Min;
    if (has && Com(Min, f[u])) {
      f[u] = Min;
      flag = 1;
    }
    if (all && Com(Max, f[u])) {
      f[u] = Max;
      flag = 1;
    }
    if (flag) {
      for (__typeof(*rev_E[u].begin()) v : rev_E[u]) {
        if (In[v]) continue;
        Q.push(v);
        In[v] = 1;
      }
    }
  }
  printf("%d\n", f[s]);
  return 0;
}
