#include <stdio.h>
#include <iostream>
#include <cstdio>
#include <algorithm> 
#include <stdio.h>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <list>
#include <utility>
#include <set>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <bitset>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <random>

using namespace std;

static const double EPS = 1e-9;
template<class T> bool INRANGE(T x, T a, T b) { return a <= x && x <= b; }
template<class T> void amin(T &a, T v) { if (a > v) a = v; }
template<class T> void amax(T &a, T v) { if (a < v) a = v; }
int ROUND(double x) { return (int)(x + 0.5); }
bool ISINT(double x) { return fabs(ROUND(x) - x) <= EPS; }
bool ISEQUAL(double x, double y) { return fabs(x - y) <= EPS * max(1.0, max(fabs(x), fabs(y))); }
double SQSUM(double x, double y) { return x * x + y * y; }
#define PI  (acos(-1))
#define ARRAY_NUM(a) (sizeof(a)/sizeof(a[0])) 
#define NG (-1)
#define BIG ((int)1e9+10)
#define BIGLL ((ll)4e18)
#define SZ(a) ((int)(a).size())
#define SQ(a) ((a)*(a))
typedef unsigned long long ull;
typedef long long ll;

/*

// MODが素数以外でも使えるバージョン。階乗の逆元を求める。
ll extgcd(ll a, ll b, ll& x, ll& y)
{
	ll d = a;
	if (b != 0)
	{
		d = extgcd(b, a%b, y, x);
		y -= (a / b)*x;
	}
	else
	{
		x = 1;
		y = 0;
	}
	return d;
}

// 逆元を求める
ll mod_inverse(ll a, ll m)
{
	ll x, y;
	extgcd(a, m, x, y);
	return (m + x % m) % m;
}

enum { NUM_FACTORIAL = 1012345 };
ll f[NUM_FACTORIAL];
ll f_inv[NUM_FACTORIAL];
ll MOD = (ll)1e9 + 7LL;

void mod_factorial_init()
{
	f[0] = 1;
	for (int i = 1; i < NUM_FACTORIAL; ++i)
	{
		f[i] = f[i - 1] * i;
		f[i] %= MOD;
	}

	for (int i = 0; i < NUM_FACTORIAL; ++i)
	{
		f_inv[i] = mod_inverse(f[i], MOD);
	}
}

// 組み合わせを求める。事前計算O(n)で、0～nまでと範囲も広いので、MODつきならパスカルの三角形よりも良い。最有力。
ll mod_comb(ll n, ll k) {
	if (k > n || n<0 || k <0)
	{
		return 0;
	}

	return ((f[n] * f_inv[k]) % MOD * f_inv[n - k]) % MOD;
}

*/

struct DIJK_LINK
{
	int from;
	int to;
	ll cost;
};

// リンクのリストから隣接リストをつくる
void dijkstra_make_G(vector< vector< pair<int, ll> > >& G, const vector < DIJK_LINK >& links, int N)
{
	G.clear();
	G.resize(N);

	for (int i = 0; i<SZ(links); i++)
	{
		G[links[i].from].push_back(make_pair(links[i].to, links[i].cost));
	}
}


void dijkstra(vector <ll>& D, const int start, const int N, const vector< vector< pair<int, ll> > >& G)
{
	D.clear();
	for (int i = 0; i<N; i++)
	{
		D.push_back(BIGLL);
	}
	priority_queue<pair<ll, int>, vector< pair<ll, int> >, greater< pair<ll, int> > > Q;
	D[start] = 0;
	Q.push(pair<ll, int>(0, start));

	while (!Q.empty()) {

		pair<ll, int> top = Q.top();
		Q.pop();

		int v = top.second;
		ll d = top.first;
		if (d <= D[v]) {
			for (int di = 0; di<SZ(G[v]); di++)
			{
				int v2 = G[v][di].first;
				ll cost = G[v][di].second;
				if (D[v2] > D[v] + cost) {
					D[v2] = D[v] + cost;
					Q.push(pair<ll, int>(D[v2], v2));
				}
			}
		}
	}
}

int main()
{
	int N, M;
	cin >> N >> M;

	vector < DIJK_LINK > links;

	vector <pair <int, int > > vp;

	for (int i = 0; i < M; ++i)
	{
		int s, t;
		cin >> s >> t;
		s--;
		t--;

		for(int m=0;m<3;m++)
		{
			DIJK_LINK tmp;
			tmp.from = s * 3 + m;
			tmp.to = t * 3 + (m+1)%3;
			tmp.cost = 1;
			links.push_back(tmp);
		}
	}

	int S, T;
	cin >> S >> T;
	S--;
	T--;

	vector< vector< pair<int, ll> > > G;
	vector <ll> D;
	dijkstra_make_G(G, links, 3*N);
	dijkstra(D, S*3, N*3, G);

	ll best = D[T*3];

	if (best >= BIG)
	{
		cout << NG << endl;
	}
	else
	{
		cout << best / 3 << endl;
	}
	return 0;
}


Measured memory_bytes: 30824