#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
int r[100001][3]={0},d[100001][3]={0};
vector<int> A[200001];
int main(){
    int n,m,u,v,s,t;
    cin>>n>>m;
    rep(i,m) cin>>u>>v,A[u].push_back(v);
    cin>>s>>t;
    queue<pair<int,int>> q;
    q.push(make_pair(s,0));
    while(!q.empty()){
        int a=q.front().first,b=q.front().second;
        q.pop();
        for(auto i:A[a]){
            if(d[i][(b+1)%3]) continue;
            d[i][(b+1)%3]=d[a][b]+1;
            q.push(make_pair(i,(b+1)%3));
        }
    }
    if(d[t][0]) cout<<d[t][0]/3;
    else cout<<-1;
}