#include <bits/stdc++.h>
using namespace std;
const long long int MOD = 1000000000 + 7;
const long long int INF = 100000000000000;
const long long int MAX = 1000000 + 10;
long long int n, m, st, en;
vector<long long int> v[MAX], adj[MAX];
long long int ans[MAX];
bool mark[MAX];
map<pair<long long int, long long int>, bool> mp;
void dijkstra() {
  set<pair<long long int, long long int> > q;
  q.insert({0, en});
  ans[en] = 0;
  mark[en] = true;
  while (q.size()) {
    long long int now = q.begin()->second;
    q.erase(q.begin());
    for (long long int i = 0; i < v[now].size(); i++) {
      long long int child = v[now][i];
      if (ans[child] != -1) continue;
      long long int num = 0;
      long long int answer_min = INF;
      long long int answer_max = -1;
      for (long long int j = 0; j < adj[child].size(); j++) {
        long long int cur = adj[child][j];
        if (ans[cur] != -1) {
          num++;
          answer_min = min(answer_min, ans[cur]);
          answer_max = max(answer_max, ans[cur]);
        }
      }
      answer_min++;
      if (num < adj[child].size()) {
        ans[child] = answer_min;
      } else {
        ans[child] = min(answer_min, answer_max);
      }
      mark[child] = true;
      q.insert({ans[child], child});
    }
  }
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  for (long long int i = 0, s, e; i < m; i++) {
    cin >> s >> e;
    v[e].push_back(s);
    adj[s].push_back(e);
  }
  for (long long int i = 1; i <= n; i++) ans[i] = -1;
  cin >> st >> en;
  dijkstra();
  cout << ans[st] << endl;
}
