#include <bits/stdc++.h>
using namespace std;
using i64 = int_fast64_t;
#define repeat(i, a, b) for(int i = (a); (i) < (b); ++(i))
#define rep(i, n) repeat(i, 0, n)

struct IoSetup {
#define endl '\n'
    IoSetup() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        // cout << fixed << setprecision(20);
        // cerr << fixed << setprecision(20);
    }
} iosetup;

namespace edamat {
template <class Info>
struct edge {
    int from, to;
    Info info;
    edge(int to, Info info) : to(to), info(info) {}
    edge(int from, int to, Info info) : from(from), to(to), info(info) {}
};

struct normal_edge {
    normal_edge() {}
};

//! graphは基底クラス！使うときはundirected_graphかdirected_graphを使う。
template <class Info>
class graph {
   protected:
    using edge_type = edge<Info>;
    ::std::size_t N;
    ::std::vector<::std::vector<edge_type>> edges;

   public:
    graph(::std::size_t N_) : N(N_), edges(N_) {}
    virtual void add_edge(int x, int y, Info info = static_cast<Info>(1)) = 0;
    const ::std::vector<edge_type> &delta(int v) const {
        assert(v < N);
        return edges[v];
    }
    const ::std::vector<edge_type> &operator[](int v) const {
        return this->delta(v);
    }
    ::std::size_t size() const { return N; }
    vector<Info> dijkstra(int s);
};

template <class Info>
class undirected_graph : public graph<Info> {
   public:
    undirected_graph(::std::size_t N) : graph<Info>(N) {}
    void add_edge(int x, int y, Info info = static_cast<Info>(1)) {
        this->edges[x].push_back(edge<Info>(x, y, info));
        this->edges[y].push_back(edge<Info>(y, x, info));
    }
};

template <class Info>
class directed_graph : public graph<Info> {
   public:
    directed_graph(::std::size_t N) : graph<Info>(N) {}
    void add_edge(int x, int y, Info info = static_cast<Info>(1)) {
        this->edges[x].push_back(edge<Info>(x, y, info));
    }
};

template <typename Info>
vector<Info> graph<Info>::dijkstra(int s) {
    const auto INF = numeric_limits<Info>::max();
    vector<Info> dist(edges.size(), INF);
    vector<int> b(edges.size(), -1);

    using Pi = pair<Info, int>;
    priority_queue<Pi, vector<Pi>, greater<Pi>> que;
    dist[s] = 0;
    que.emplace(dist[s], s);
    while(!que.empty()) {
        Info cost;
        int idx;
        tie(cost, idx) = que.top();
        que.pop();
        if(dist[idx] < cost) continue;
        for(auto &e : edges[idx]) {
            auto next_cost = cost + e.info;
            if(dist[e.to] <= next_cost) continue;
            dist[e.to] = next_cost;
            b[e.to] = idx;
            que.emplace(dist[e.to], e.to);
        }
    }
    return dist;
}

}  // namespace edamat

/*
 * https://atcoder.jp/contests/abc132/tasks/abc132_e
 */
void ABC132_E() {
    i64 N, M;
    cin >> N >> M;
    edamat::directed_graph<i64> g(3 * N);
    while(M--) {
        i64 u, v;
        cin >> u >> v;
        u--, v--;
        g.add_edge(u, v + N);
        g.add_edge(u + N, v + 2 * N);
        g.add_edge(u + 2 * N, v);
    }
    i64 S, T;
    cin >> S >> T;
    S--, T--;
    vector<i64> dist(3 * N, -1);
    // * BFS
    // queue<i64> q;
    // q.push(S);
    // dist[S] = 0;
    // while(!q.empty()) {
    //     i64 v = q.front();
    //     q.pop();
    //     for(auto e : g[v]) {
    //         if(dist[e.to] != -1) continue;
    //         dist[e.to] = dist[e.from] + e.info;
    //         q.push(e.to);
    //     }
    // }
    // * dijkstra
    dist = g.dijkstra(S);
    cout << (dist[T] == numeric_limits<i64>::max() ? -1 : dist[T] / 3) << endl;
};

int main() {
    ABC132_E();
    return 0;
};

Measured memory_bytes: 22528