#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 5, inf = 0x3f3f3f3f;

vector<int> g[3 * maxn];
int d[3 * maxn];

int main()
{
    ios::sync_with_stdio(0); cin.tie(0);

    int n, m;
    cin >> n >> m;
    while (m--){
        int u, v;
        cin >> u >> v;
        //模3循环，点分成3层，模3为0的u连到模3为1的v，后面同理
        g[3 * u].push_back(3 * v + 1);
        g[3 * u + 1].push_back(3 * v + 2);
        g[3 * u + 2].push_back(3 * v);
    }

    int s, t;
    cin >> s >> t;

    queue<int> qi;
    qi.push(3 * s);
    while (!qi.empty()){
        int u = qi.front(); qi.pop();
        for (int v : g[u]) if (!d[v]) {
            d[v] = d[u] + 1;
            qi.push(v);
        }
    }

    cout << (d[3 * t] ? d[3 * t] / 3 : -1) << endl;
    return 0;
}
