#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
using PP = pair<int, int>;
int n, m, s, t;
vector<int> G[300000];

int bfs() {
  vector<int> dist(3 * n, INF);
  queue<PP> Q;
  Q.push(PP(0, s));
  while (!Q.empty()) {
    PP p = Q.front(); Q.pop();
    int d = p.first;
    int from = p.second;
    if (dist[from] != INF) continue;
    dist[from] = d;
    for (int to : G[from]) {
      Q.push(PP(d + 1, to));
    }
  }
  return dist[t];
}

int main() {
  cin >> n >> m;
  for (int j = 0; j < m; ++j) {
    int a, b;
    cin >> a >> b;
    --a; --b;
    for (int k = 0; k < 3; ++k) {
      G[a + k * n].push_back(b + (k + 1) % 3 * n);
    }
  }
  cin >> s >> t;
  --s; --t;
  int ans = bfs();
  cout << (ans == INF ? -1 : ans / 3) << endl;
}