#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+10,inf=1e9;
int dp[maxn][3],n,m;
bool vis[maxn][3];
vector<int> a[maxn];
struct pa{
    int val,nod,l;
}p;
int main(){
    int u,v;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;i++){
        scanf("%d%d",&u,&v);
        a[u].push_back(v);
    }
    for(int i=1;i<=n;i++)
        for(int j=0;j<3;j++)
        dp[i][j]=inf;
    scanf("%d%d",&u,&v);
    dp[u][0]=0;
    queue<pa> q;
    q.push({0,u,0});
    while(!q.empty()){
        p=q.front();q.pop();
        if(vis[p.nod][p.l])continue;
        vis[p.nod][p.l]=true;
        for(int i:a[p.nod]){
            if(!vis[i][(p.l+1)%3]){
                dp[i][(p.l+1)%3]=p.val+1;
                q.push({p.val+1,i,(p.l+1)%3});
            }
        }
    }
    printf("%d\n",dp[v][0]==inf?-1:dp[v][0]/3);
}
