#include <stdio.h>
#include <iostream>
#include <string.h>
#include <limits.h>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <queue>

#ifndef ULLONG
typedef unsigned long long ULLONG;
#endif
#ifndef LLONG
typedef long long LLONG;
#endif

typedef std::pair<int, int> IntPair;

template <class _T> static _T tp_abs(const _T& a) {
	return ((a < 0) ? (a * -1) : a);
}
template <class _T> static _T tp_min(_T a, _T b) {
	return a < b ? a : b;
}
template <class _T> static _T tp_max(_T a, _T b) {
	return a > b ? a : b;
}
template<class _T> static void get1int(_T& a) {
	const char* fmt = " %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld";
	}

	if (scanf(fmt, &a) < 0) {
		printf("g1int Error\n");
	}
}
template<class _T> static void get2int(_T& a, _T& b) {
	const char* fmt = " %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld";
	}

	if (scanf(fmt, &a, &b) < 0) {
		printf("g2int Error\n");
	}
}
template<class _T> static void get3int(_T& a, _T& b, _T& c) {
	const char* fmt = " %d %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld %lld";
	}

	if (scanf(fmt, &a, &b, &c) < 0) {
		printf("g3int Error\n");
	}
}

static const LLONG Dmod = 1000000007;
static const int ABC132_INF = 100000000;

static void E_task();

int main()
{
	E_task();
	
	fflush(stdout);
	return 0;
}

class UniEdge
{
public:
	int _to = -1;
	int _cost = -1;

	UniEdge() {}
	UniEdge(int to, int cost) {
		_to = to;
		_cost = cost;
	}

	static bool sort_by_cost_asc(const UniEdge& a, const UniEdge& b) {
		return (a._cost < b._cost);
	}
};


static int E_dfs(std::vector<std::vector<int>>& edge, int nowNode, int goal, int pathNo, int nowDist)
{
	static int dp[300000] = { 0 };

	if (dp[nowNode] != 0) {
		return dp[nowNode];
	}

	if (nowNode == goal) {
		if ((nowDist % 3) == 0) {
			return nowDist;
		}
		else {
			return ABC132_INF;
		}
	}

	int ret = ABC132_INF;
	for (int i = 0; i < edge[nowNode].size(); i++) {
		int dist = E_dfs(edge, edge[nowNode][i], goal, pathNo, nowDist + 1);
		ret = tp_min<int>(ret, dist);
		dp[nowNode] = dist;
	}
	return ret;
}

//--------------------------------------------------------------------
// P96 単一始点最短経路問題2 ダイクストラ法2 ヒープを使う
//--------------------------------------------------------------------
static void P96_dijkstra2(int sttVtx, int* path, int vCount, const std::vector<std::vector<UniEdge>>& edge)
{
	std::priority_queue<IntPair, std::vector<IntPair>, std::greater<IntPair>> queue;
	std::fill(path, path + vCount, ABC132_INF);

	//	指定された点のみ確定
	path[sttVtx] = 0;
	queue.push(IntPair(0, sttVtx));

	while (!queue.empty()) {
		IntPair p = queue.top(); queue.pop();
		int vtx = p.second;
		if (path[vtx] < p.first) {
			continue;
		}

		int eCount = edge[vtx].size();
		for (int i = 0; i < eCount; i++) {
			UniEdge ue = edge[vtx][i];
			if (path[ue._to] > path[vtx] + ue._cost) {
				path[ue._to] = path[vtx] + ue._cost;
				queue.push(IntPair(path[ue._to], ue._to));
			}
		}
	}
}

static void E_task()
{
	int N, M;
	get2int(N, M);

	std::vector<std::vector<UniEdge>> evec(N * (int)3 + 1);
	auto path = new int[N * 3 + 1];

	for (int i = 0; i < M; i++) {
		int u, v;
		get2int(u, v);

		UniEdge tmp;
		tmp._cost = 1;
		int k = 1;
		for (int j = 0; j < 3; j++) {
			tmp._to = (v - 1) * 3 + k;
			evec[(u - (int)1) * (int)3 + j].push_back(tmp);
			k = (++k) % 3;
		}
	}
	int start, goal;
	get2int(start, goal);
	start = (start - 1) * 3;
	goal = (goal - 1) * 3;

	P96_dijkstra2(start, path, N * 3, evec);

	int ans = -1;
	if ((path[goal] % 3) == 0) {
		ans = path[goal] / 3;
	}
	printf("%d\n", ans);
	delete[] path;
}


Measured memory_bytes: 17792