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

int n, m, a, b, p1, p2;
vector<int> v[100002];
int bio[100002][5];
queue< pair<int, int> > q;

void bfs() {
	
	while (!q.empty()) {
		int x = q.front().X;
		int y = q.front().Y;
		q.pop();
		for (int i = 0; i < v[x].size(); i ++) {
			int sus = v[x][i];
			if (bio[sus][(y+1) % 3] == -1) {
				bio[sus][(y+1) % 3] = bio[x][y]+1;
				q.push({sus, (y+1)%3});
			}
		}
	}

}

int main () {

	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		cin >> a >> b;
		v[a].push_back(b);
	}
	
	cin >> p1 >> p2;
	memset(bio, -1, sizeof bio);
	bio[p1][0] = 0;
	q.push({p1, 0});
	bfs();
	if (bio[p2][0] == -1) cout << -1;
	else cout << bio[p2][0]/3;

	return 0;
}