#include<iostream>
#include<vector>
#include <algorithm>
#include <string>
#include <utility>
#include <set>
#include <map>
#include<cmath>
#include <queue>
#include <numeric>

using lli = long long int;
int inf = 1000000007;
using namespace std;

int N, M;
int u, v;
int S, T;

int main()
{
	cin >> N >> M;
	vector<vector<int>> G(3 * N + 1);
	vector<int> cost(3 * N + 1, -3);
	for (int i = 0; i < M; i++) {
		cin >> u >> v;
		G[u].push_back(v + N);
		G[u + N].push_back(v + 2 * N);
		G[u + 2 * N].push_back(v);
	}
	cin >> S >> T;
	queue<int> q;
	q.push(S);
	cost[S] = 0;
	while (q.size() != 0) {
		int now = q.front();
		q.pop();
		for (auto e : G[now]) {
			if (cost[e] == -3) {
				cost[e] = cost[now] + 1;
				q.push(e);
			}
		}
	}
	cout << cost[T] / 3 << endl;
	return 0;
}