#include <vector>
#include <queue>
#include <iostream>
#include <queue>
#include <utility>
#include <tuple>
using namespace std;
constexpr int INF = 1e9;

int main(){
  int N, M;
  cin >> N >> M;
  vector<vector<int>> G(N);
  for(int i = 0; i < M; ++i){
    int u, v;
    cin >> u >> v;
    --u,--v;
    G[u].push_back(v);
  }
  int s, t;
  cin >> s >> t;
  --s,--t;
  vector<vector<int>> D(N,vector<int>(3,INF));
  D[s][0] = 0;
  queue<pair<int,int>> Q;
  Q.emplace(s,0);
  while(Q.size()){
    int v, d;
    tie(v,d) = Q.front();
    Q.pop();
    int c = D[v][d] + (d == 0);
    int d_ = (d+1)%3;
    for(auto v_ : G[v]){
      if(D[v_][d_] <= c) continue;
      D[v_][d_] = c;
      Q.emplace(v_,d_);
    }
  }
  if(D[t][0] >= INF){
    cout << -1 << endl;
    return 0;
  }
  cout << D[t][0] << endl;
}
