// #include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <math.h>
#include <iomanip>
#include <iterator>
using namespace std;
#define PB push_back
#define MP make_pair
#define f first
#define s second
#define FOR(i,a,b) for (int i = a; i < b; ++i)
#define RFOR(i, b, a) for (int i = b-1; i>=a; --i)
#define FILL(a, b) memset(a, b, sizeof a)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)a.size()
typedef long long LL;
typedef pair<double, double> PII;
typedef vector<int> VI;
typedef vector<LL> VLL;
typedef pair<LL, LL> PLL;
const int INF = 1000 * 1000 * 1000;
const LL LINF = 1LL * INF * INF;
const long double PI = acos(-1.);
const double EPS = 1e-6;
LL mod = INF + 7;
const int maxn = 3*100010;
VI g[maxn];
int d[maxn];
int q[maxn];
int main()
{
// freopen("input.txt","r",stdin);
int n,m;
cin >> n >> m;
FOR(i,0,m)
{
int a,b;
cin >> a >> b;
a--;b--;
g[3*a].PB(3*b+1);
g[3*a+1].PB(3*b+2);
g[3*a+2].PB(3*b);
}
int s,t;
cin >> s >> t;
s--; t--;
FOR(i,0,maxn)
d[i] = INF;
d[3*s] = 0;
int qh = 0,qt = 0;
q[qh++] = 3*s;
while(qh!=qt)
{
int v = q[qt++];
FOR(i,0,SZ(g[v]))
{
if(d[g[v][i]]!=INF) continue;
q[qh++] = g[v][i];
d[g[v][i]] = d[v] + 1;
}
}
if(d[3*t]==INF)
{
cout << -1;
}
else
{
cout << d[3*t]/3;
}
return 0;
}
Ly8gI2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiNpbmNsdWRlIDxpb3N0cmVhbT4KI2luY2x1ZGUgPHZlY3Rvcj4KI2luY2x1ZGUgPHN0cmluZz4KI2luY2x1ZGUgPG1hcD4KI2luY2x1ZGUgPHNldD4KI2luY2x1ZGUgPGNtYXRoPgojaW5jbHVkZSA8YWxnb3JpdGhtPgojaW5jbHVkZSA8bWF0aC5oPgojaW5jbHVkZSA8aW9tY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S0tO2ItLTsKICAgICAgICBnWzMqYV0uUEIoMypiKzEpOwogICAgICAgIGdbMyphKzFdLlBCKDMqYisyKTsKICAgICAgICBnWzMqYSsyXS5QQigzKmIpOwogICAgfQogICAgaW50IHMsdDsKICAgIGNpbiA+PiBzID4+IHQ7CiAgICBzLS07IHQtLTsKICAgIEZPUihpLDAsbWF4bikKICAgICAgICBkW2ldID0gSU5GOwogICAgZFszKnNdID0gMDsKICAgIGludCBxaCA9IDAscXQgPSAwOwogICAgcVtxaCsrXSA9IDMqczsKICAgIHdoaWxlKHFoIT1xdCkKICAgIHsKICAgICAgICBpbnQgdiA9IHFbcXQrK107CiAgICAgICAgRk9SKGksMCxTWihnW3ZdKSkKICAgICAgICB7CiAgICAgICAgICAgIGlmKGRbZ1t2XVtpXV0hPUlORikgY29udGludWU7CiAgICAgICAgICAgIHFbcWgrK10gPSBnW3ZdW2ldOwogICAgICAgICAgICBkW2dbdl1baV1dID0gZFt2XSArIDE7ICAgIAogICAgICAgIH0KICAgIH0KCgogICAgaWYoZFszKnRdPT1JTkYpCiAgICB7CiAgICAgICAgY291dCA8PCAtMTsKICAgIH0KICAgIGVsc2UKICAgIHsKICAgICAgICBjb3V0IDw8IGRbMyp0XS8zOwogICAgfQogICAgCiAgICByZXR1cm4gMDsKfQ==