#include <bits/stdc++.h>
#define X first
#define Y second
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

const ll Q = (ll)(1e9) + 7;
const int MAXN = 1e5+1;

vector<int> nxt[MAXN];
vector<pii> q;
bool used[3][MAXN];
int dist[3][MAXN];



int main() {
	ios_base::sync_with_stdio(0);

	int n, m;
	cin >> n >> m;
	while(m--) {
		int x, y;
		cin >> x >> y;
		nxt[x].push_back(y);
	}
	int s, t;
	cin >> s >> t;
	q.push_back({s,0});
	used[0][s] = 1;
	for(int i = 0; i < q.size(); i++) {
		int v = q[i].X;
		int d = q[i].Y;
		for(int w : nxt[v]) {
			int dd = (d+1)%3;
			if(!used[dd][w]) {
				used[dd][w] = 1;
				dist[dd][w] = dist[d][v] + 1;
				q.push_back({w,dd});
			}
		}
	}

	cout << (used[0][t] ? dist[0][t]/3 : -1) << '\n';

	return 0;
}