#include <bits/stdc++.h>
using namespace std;
struct road {
  int first, next;
} r[1000005];
int N, M;
int S, T;
int st[1000005], w;
int dis[1000005], vis[1000005], lad[1000005];
queue<int> q;
set<pair<int, int> > have[1000005];
set<pair<int, int> >::iterator it;
void add(int first, int second) {
  r[++w].first = second, r[w].next = st[first];
  st[first] = w;
}
void SPFA() {
  int i, j, tmp, first, to;
  memset(lad, 63, sizeof(lad));
  memset(dis, 63, sizeof(dis));
  q.push(T), dis[T] = 0;
  for (i = 1; i <= N; i++)
    for (j = st[i]; j; j = r[j].next)
      have[r[j].first].insert(make_pair(lad[i], i));
  while (!q.empty()) {
    first = q.front(), q.pop();
    vis[first] = 0;
    for (i = st[first]; i; i = r[i].next) {
      tmp = r[i].first;
      it = have[tmp].lower_bound(make_pair(lad[first], first));
      have[tmp].erase(it);
      have[tmp].insert(make_pair(dis[first], first));
      it = have[tmp].begin(), to = (*it).first + 1;
      it = have[tmp].end(), it--, to = min(to, (*it).first);
      if (dis[tmp] > to) {
        dis[tmp] = to;
        if (!vis[tmp]) vis[tmp] = 1, q.push(tmp);
      }
    }
    lad[first] = dis[first];
  }
}
int main() {
  int i, j;
  int fr, to;
  scanf("%d %d", &N, &M);
  for (i = 1; i <= M; i++) {
    scanf("%d %d", &fr, &to);
    add(to, fr);
  }
  scanf("%d %d", &S, &T);
  SPFA();
  if (dis[S] + 10 >= dis[0])
    printf("-1\n");
  else
    printf("%d\n", dis[S]);
  return 0;
}
