#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#include <iomanip>
#include <complex>
#include <bitset>
#include <stack>
using namespace std;
 
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define repl(i,s,n) for(int i=s; i<=n; ++i)
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define ktya(x) sort(all(x))
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 1e18
#define INFLL 1000000000000000007LL
#define SIZE 200105
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mind(a,b) (a>b?b:a)
#define maxd(a,b) (a>b?a:b)
#define PI (acos(-1))
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
typedef pair<int,ll> pill; typedef pair<ll,int> plli; 
typedef pair<double, int> pdi;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
typedef complex<double> P;
// ll MOD = 1000000007;
ll MOD=998244353;
typedef ll Weight;
struct Edge {
	int src, dst;
	Weight weight;
};
bool operator < (const Edge &e, const Edge &f) {
	return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
	e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;//複数辺があるとき用。基本使わない
typedef vector<Edges> Graph;//G[頂点]がEdges(つまりベクトル)になるのでここに辺をつっこむ。
//
int N,M,K;
vi Gr[314514];

void shortestPath(const Graph &g, int s,
				  vector<Weight> &dist, vector<int> &prev) {
	int n = g.size();
	dist.assign(n, INF); dist[s] = 0;
	prev.assign(n, -1);
	priority_queue<Edge> Q; // "e < f" <=> "e.weight > f.weight"
	Edge hoge={-2, s, 0};
	for (Q.push(hoge); !Q.empty(); ) {
		Edge e = Q.top(); Q.pop();
		if (prev[e.dst] != -1) continue;
		prev[e.dst] = e.src;
		FOR(f,g[e.dst]) {
						 if (dist[f->dst] > e.weight+f->weight) {
																 dist[f->dst] = e.weight+f->weight;
				Edge fuga={f->src, f->dst, e.weight+f->weight};
				Q.push(fuga);
			}
		}
	}
}
int main(){
	cin>>N>>M;
	Graph Gph(3*N);
	rep(i,M){
		int x,y;
		cin>>x>>y;x--;y--;
		Edge hen={3*x,3*y+1,1};
		Gph[3*x].pb(hen);
		Edge hen2={3*x+1,3*y+2,1};
		Gph[3*x+1].pb(hen2);
		Edge hen3={3*x+2,3*y,1};
		Gph[3*x+2].pb(hen3);
	}
	vector<Weight> ans;
	vi hoge;
	int st,ed;
	cin>>st>>ed;
	st--;ed--;
	shortestPath(Gph,3*st,ans,hoge);
	if(ans[ed*3]>=INF)ans[ed*3]=-3;
	cout<<ans[ed*3]/3<<endl;
	//rep(i,3*N)cout<<i/3<<" "<<ans[i]<<endl;
}

Measured memory_bytes: 29056