#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using dd = double;
using vi = vector<int>;
using vl = vector<ll>;
using vd = vector<dd>;
using vb = vector<bool>;

template <class T, class V>
istream& operator>>(istream& in, pair<T, V>& pair) {
    return in >> pair.first >> pair.second;
}

template <class T>
istream& operator>>(istream& in, vector<T>& elements) {
    for (size_t i = 0; i < elements.size(); ++i) {
        in >> elements[i];
    }
    return in;
}

template <class Container, class Element>
bool Contains(const Container& container, const Element& element) {
    return container.find(element) != container.end();
}

template <class T>
ostream& operator<<(ostream& out, const vector<T>& elements) {
    for (const T& element : elements) {
        out << element << ' ';
    }
    return out;
}

template <class T, class V>
ostream& operator<<(ostream& out, const pair<T, V>& pair) {
    out << pair.first << ' ' << pair.second;
}

#define FOR(i,n) for(size_t i=0, i##_len=(n); i<i##_len; ++i)
#define SORT(c) sort((c).begin(), (c).end())

using Graph = vector<unordered_set<int>>;

int main() {
    ios_base::sync_with_stdio(false);
    
    int n, m;
    cin >> n >> m;
    
    Graph g(3 * n);
    FOR(i, m) {
        int u, v;
        cin >> u >> v;
        --u; --v;
        
        g[3 * u].insert(3 * v + 1);
        g[3 * u + 1].insert(3 * v + 2);
        g[3 * u + 2].insert(3 * v);
    }
    
    int s, t;
    cin >> s >> t;
    s = (s - 1) * 3;
    t = (t - 1) * 3;
    
    
    queue<int> q;
    vb used(3 * n);
    vi dist(3 * n, -1);
    
    q.push(s);
    used[s] = true;
    dist[s] = 0;
    
    while (!q.empty()) {
        int v = q.front();
        q.pop();
        
        assert(used[v]);
        for (int next : g[v]) {
            if (used[next]) {
                continue;
            }
            used[next] = true;
            dist[next] = dist[v] + 1;
            q.push(next);
        }
    }
    
    assert(dist[t] == -1 || dist[t] % 3 == 0);
    cout << ((dist[t] == -1) ? -1 : dist[t] / 3) << endl;
    
    return 0;
}
