#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
vector<int> v[N], vf[N];
int n, m, st, ed;
queue<int> q;
bool in[N];
int d[N];
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  int x, y, l, mx;
  for (register int i = (1); i <= (m); ++i) {
    cin >> x >> y;
    v[x].push_back(y);
    vf[y].push_back(x);
  }
  for (register int i = (1); i <= (n); ++i) d[i] = -1;
  cin >> st >> ed;
  d[ed] = 0;
  q.push(ed);
  while (q.size()) {
    x = q.front();
    q.pop();
    in[x] = 0;
    l = vf[x].size();
    for (register int i = (0); i <= (l - 1); ++i) {
      y = vf[x][i];
      if (d[y] == -1 || d[y] > d[x] + 1) {
        d[y] = d[x] + 1;
        if (!in[y]) q.push(y), in[y] = 1;
      }
    }
    l = v[x].size();
    mx = -1;
    for (register int i = (0); i <= (l - 1); ++i) {
      y = v[x][i];
      if (d[y] == -1) {
        mx = -1;
        break;
      }
      mx = max(mx, d[y]);
    }
    if (mx == -1) continue;
    if (d[x] > mx) {
      d[x] = mx;
      if (!in[x]) q.push(x), in[x] = 1;
    }
  }
  cout << d[st] << '\n';
  return 0;
}
