#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//ここから編集する
class Dijkstra {
public:
    using T = long long int;
    typedef pair<T, int> P; //firstは最短距離、secondは頂点の番号
    const T inf = (T) 5e15;
    struct edge {
        int to;
        T cost;
    };

    int V;                  //超点数
    vector<vector<edge>> G; //グラフ,G[i]はiから出る辺の集合,G[i][j]はiから出る辺のj番目の辺
    vector<T> d;           //最短距離

    //0origin
    Dijkstra(int N) {
        V = N;
        G = vector<vector<edge >>(N);
        d = vector<T>(N);
    };

    void dijkstra(int s) {
        priority_queue<P, vector<P>, greater<P>> que;
        fill(d.begin(), d.end(), inf);
        d[s] = 0;
        que.push(P(0, s));

        while (!que.empty()) {
            P p = que.top();
            que.pop();
            int v = p.second;
            if (d[v] < p.first)
                continue;
            for (int i = 0; i < G[v].size(); i++) {
                edge e = G[v][i];
                if (d[e.to] > d[v] + e.cost && !(d[e.to] == inf && d[v] == inf)) {
                    d[e.to] = d[v] + e.cost;
                    que.push(P(d[e.to], e.to));
                }
            }
        }
    }

    /* 頂点fromに頂点toに達するコストcostの辺を貼る */
    void addEdge(int from, int to, T cost) {
        edge e;
        e.to = to;
        e.cost = cost;
        G[from].push_back(e);
    }

    T getDist(int v) {
        return d[v];
    }
};

struct SCC {
    int V;
    vector<vector<int> > G;//グラフの隣接リスト表現
    vector<vector<int> > rG;//変の向きを逆にしたグラフ
    vector<int> vs;//帰りがけ順の並び
    vector<bool> used;//既に調べたか
    vector<int> cmp;//属する共連結成分のトポロジカル順序

    SCC(int v) {
        V = v;
        G.resize(V);
        rG.resize(V);
        used.resize(V);
        cmp.resize(V);
    }

    /**
     * 辺を貼る
     * @param from 辺の元
     * @param to 辺の先
     */
    void add_edge(int from, int to) {
        G[from].push_back(to);
        rG[to].push_back(from);
    }

    void dfs(int v) {
        used[v] = true;
        for (int i = 0; i < G[v].size(); i++) {
            if (!used[G[v][i]]) dfs(G[v][i]);
        }
        vs.push_back(v);
    }


    void rdfs(int v, int k) {
        used[v] = true;
        cmp[v] = k;
        for (int i = 0; i < rG[v].size(); i++) {
            if (!used[rG[v][i]]) rdfs(rG[v][i], k);
        }
    }

    int scc() {
        fill(used.begin(), used.end(), false);
        vs.clear();
        for (int v = 0; v < V; v++) {
            if (!used[v]) dfs(v);
        }
        fill(used.begin(), used.end(), false);
        int k = 0;
        for (int i = vs.size() - 1; i >= 0; i--) {
            if (!used[vs[i]]) rdfs(vs[i], k++);
        }
        return k;
    }
};

class Solve {
public:
    int N, M;
    vector<pair<int, int> > edges;
    int S, T;

    void input() {
        cin >> N >> M;
        for (int i = 0; i < M; ++i) {
            int u, v;
            cin >> u >> v;
            u--, v--;
            edges.push_back(make_pair(u, v));
        }
        cin >> S >> T;
        S--, T--;

    }

    void solve() {
        input();
        Dijkstra dij(3 * N);
        auto conv = [&](int v, int layer) {
            return v + layer * N;
        };

        for (auto edge : edges) {
            int u = edge.first;
            int v = edge.second;
            for (int i = 0; i < 3; ++i) {
                int uu = conv(u, i % 3);
                int vv = conv(v, (i + 1) % 3);
                dij.addEdge(uu, vv, 1);
            }
        }

        int s = S;
        int g = T;
        dij.dijkstra(s);
        ll ans = dij.getDist(g);
        if (ans == INFl) {
            cout << -1 << endl;
        } else {
            cout << ans / 3 << endl;
        }
    }
};


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    Solve().solve();


    return 0;
}


Measured memory_bytes: 19828