#include <bits/stdc++.h>
#define N ((int)1e5+5)
using namespace std;
int main(){
	// interesting
	int n,m;
	cin>>n>>m;
	vector<vector<int>> gra(N);
	for(int i=0;i<m;i++){
		int u,v;
		cin>>u>>v;
		u-=1;
		v-=1;
		gra[u].emplace_back(v);
	}
	int s,t;
	cin>>s>>t;
	s-=1;
	t-=1;
	queue<pair<int,int>> q;
	q.push(make_pair(0,s));
	vector<int> flag(3*n,-3);
	int dfsParent[3*n];
	memset(dfsParent,0,sizeof(dfsParent));
	while(!q.empty()){
		pair<int,int> nx=q.front();q.pop();
		int nxdis=nx.first;
		int nxpoi=nx.second;
		if(flag[nxpoi]!=-3)continue;
		flag[nxpoi]=nxdis;
		for(int i=0;i<(int)gra[nxpoi%n].size();i++){
			int nx=gra[nxpoi%n][i];
			q.push(make_pair(nxdis+1,(nxdis+1)%3*n+nx));
			dfsParent[(nxdis+1)%3*n+nx]=nxpoi;
		}
	}
	cout<<flag[t]/3<<endl;
	
	return 0;
}