#include <bits/stdc++.h>
using namespace std;

int n,m;
vector<vector<int>> e;
vector<int> length;
queue<int> vertex;

void bfs(int i){
  for(int x:e[i]){
    if(length[(x+n)%(3*n)]>length[i]+1){
      length[(x+n)%(3*n)]=length[i]+1;
      vertex.push((x+n)%(3*n));
    }
  }
}

int main(){
  cin>>n>>m;
  e.resize(3*n);
  length.resize(3*n);
  for(int i=0; i<3*n; ++i)length[i]=1000000000;
  
  for(int i=0; i<m; ++i){
    int u,v; cin>>u>>v;
    e[u-1].push_back(v-1+n);
    e[u-1+n].push_back(v-1+2*n);
    e[u-1+2*n].push_back(v-1);
  }
  int s,t; cin>>s>>t;

  length[s-1]=0;
  vertex.push(s-1);
  while(!vertex.empty()){
    bfs(vertex.front());
    vertex.pop();
  }

  if(length[t-1]==1000000000)cout<<-1<<endl;
  else cout<<length[t-1]/3<<endl;
}
