#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
using namespace std;

typedef pair <int, int> pii;
typedef pair <pii, int> piii;

vector <int> from[100010];
int vis[100010][3];
queue <piii> q;

int main(){
	int n, m; scanf("%d%d", &n, &m);
	for (int i = 0; i < m; i++){
		int u, v; scanf("%d%d", &u, &v);
		from[u].push_back(v);
	}
	int S, T; scanf("%d%d", &S, &T);
	memset(vis, -1, sizeof(vis));
	q.push(mp(mp(S, 0), 0)), vis[S][0] = 0;
	while (!q.empty()){
		piii t = q.front(); q.pop();
		int x = t.fi.fi, p = (t.fi.se + 1) % 3, dist = t.se + 1;
		for (int i = 0; i < from[x].size(); i++){
			int v = from[x][i];
			if (~vis[v][p]) continue;
			vis[v][p] = dist, q.push(mp(mp(v, p), dist));
		}
	}
	printf("%d\n", vis[T][0] == -1 ? -1 : vis[T][0] / 3);
	return 0;
}
