#include <bits/stdc++.h>

#define TYPE(c)   remove_reference_t<decltype(c)>
#define REP(i, n) for(TYPE(n) i = 0; i < n; i++)
#define FOR(v, c) for(TYPE(c.begin()) v = c.begin(); v != c.end(); v++)
#define ALL(c)    c.begin(), c.end()
#define SORT(c)   sort(ALL(c))
#define RSORT(c)  sort(ALL(c), greater<TYPE(c)::value_type>())
#define UNIQUE(c) c.erase(unique(ALL(c)), c.end())

using namespace std;
using ll = long long;

constexpr int MOD  = (int)1e9 + 7;
constexpr int INF  = (int)1e9 + 1;
constexpr ll  LINF = (ll)1e18 + 1;
template<typename T> constexpr bool chmax(T& a, const T& b)
{ if(a < b) { a = b; return true; } else { return false; } }
template<typename T> constexpr bool chmin(T& a, const T& b)
{ if(b < a) { a = b; return true; } else { return false; } }
template<typename S, typename T> ostream& operator<<(ostream &os, const pair<S, T>& p)
{ return os << "(" << p.first << "," << p.second << ")"; }
template<typename T> auto operator<<(ostream& os, const T& t)
    -> typename conditional<true, ostream&, decltype(*t.begin())>::type
{ os << "["; FOR(v, t) { if(v != t.begin()) os << ","; os << *v; } os << "]"; return os; }

class Graph {
    using ll = long long;
public:
    enum class Type { Directed, Undirected };
    struct Edge {
        ll   cost;
        bool validity;
        explicit Edge(const ll& _cost) :
            cost(_cost), validity(true) { }
        friend std::ostream& operator <<(std::ostream& os, std::shared_ptr<Edge>& e){
            os<<"cost : "<< e->cost<<", "<<"validity : "<< e->validity;return os;
        }
    };
    struct Vertex {
        ll cost;
        explicit Vertex(const ll& _cost) : cost(_cost) { }
        friend std::ostream& operator <<(std::ostream& os, const Vertex& v) {
            os<<"cost : "<<v.cost;return os;
        }
    };
    const Type edge_type;
    std::vector<Vertex> vertices;
    std::vector<std::map<ll, std::shared_ptr<Edge>>> edges;
    Graph(const ll& nof_vertex, const Type& edge_type, const ll& vertices_initial_cost = (ll)1e9 + 1) :
        edge_type(edge_type), vertices(nof_vertex, Vertex(vertices_initial_cost)), edges(nof_vertex) { }
    void setCostToAllVertices(const ll& val) {
        std::fill(vertices.begin(), vertices.end(), Vertex(val));
    };
    void addEdge(const ll& src, const ll& dst, const ll& cost = 1) {
        auto edge = std::make_shared<Edge>(cost);
        edges[src].emplace(dst, edge);
        if(edge_type == Type::Undirected) edges[dst].emplace(src, edge);
    }
    friend std::ostream& operator <<(std::ostream& os, const Graph& g) {
        os<<std::endl
          <<"--- Vertex Information ---"<<std::endl;
        for(size_t i=0;i<g.vertices.size();i++)os<<"[["<<i<<"] "<<g.vertices[i]<<"]"<<std::endl;
        os<<"---- Edge Information ----"<<std::endl;
        for(size_t i=0;i<g.vertices.size();i++)for(auto&e:g.edges[i])os<<"["<<i<<" -> "<<e.first<<"] "<<"["<<e.second<<"]"<<std::endl;
        os<<"--------------------------";
        return os;
    }
};

/**
 *  全ての頂点に対してある頂点からの最短経路を求める(dijkstra法)
 *  NOTE: 計算量O(|E|log|V|), Dependencies: comp-Graph,
 *        始点と非連結の頂点は更新しない
 */
// 使用例
// g.setCostToAllVertex(inf_val);
// dijkstra(g, start_index);
// std::cout << g.vertex[specific_index] << std::endl;
void dijkstra(Graph&     g,
              const int& start_index) {
    using pll = std::pair<ll, ll>;
    g.vertices[start_index].cost = 0;
    std::priority_queue<pll, std::vector<pll>, std::greater<pll>> pq;
    pq.emplace(0, start_index);
    while(!pq.empty()) {
        auto top = pq.top();
        pq.pop();
        if(g.vertices[top.second].cost < top.first) continue;
        for(const auto& e : g.edges[top.second]) {
            auto cost = g.vertices[top.second].cost + e.second->cost;
            if(cost < g.vertices[e.first].cost) {
                g.vertices[e.first].cost = cost;
                pq.emplace(g.vertices[e.first].cost, e.first);
            }
        }
    }
}

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

    int N, M;
    std::cin >> N >> M;

    Graph g(N * 3, Graph::Type::Directed, INF);

    REP(i, M) {
        int l, r;
        std::cin >> l >> r;
        g.addEdge((l - 1) * 3 + 0 , (r - 1) * 3 + 1, 1);
        g.addEdge((l - 1) * 3 + 1 , (r - 1) * 3 + 2, 1);
        g.addEdge((l - 1) * 3 + 2 , (r - 1) * 3 + 0, 1);
    }

    int S, T;
    std::cin >> S >> T;

    auto start = (S - 1) * 3;
    auto goal  = (T - 1) * 3;

    dijkstra(g, start);

    std::cout << (g.vertices[goal].cost != INF ? g.vertices[goal].cost / 3 : -1) << std::endl;

    return 0;
}


Measured memory_bytes: 49536