#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 {
    IoSetup() {
        std::cin.tie(nullptr);
        std::ios::sync_with_stdio(false);
        // std::cout << std::fixed << std::setprecision(20);
        // std::cerr << std::fixed << std::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; }
    ::std::vector<Info> bfs(int);
    ::std::vector<Info> dijkstra(int);
};

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>
std::vector<Info> graph<Info>::bfs(int s) {
    const auto INF = std::numeric_limits<Info>::max();
    std::vector<Info> dist(edges.size(), INF);
    std::vector<int> b(edges.size(), -1);  // 経路復元

    std::queue<Info> q;
    q.push(s);
    dist[s] = 0;
    while(!q.empty()) {
        Info v = q.front();
        q.pop();
        for(auto e : edges[v]) {
            if(dist[e.to] != INF) continue;
            dist[e.to] = dist[e.from] + e.info;
            b[e.to] = e.from;  // 経路復元
            q.push(e.to);
        }
    };
    return dist;
}

template <typename Info>
std::vector<Info> graph<Info>::dijkstra(int s) {
    const auto INF = std::numeric_limits<Info>::max();
    std::vector<Info> dist(edges.size(), INF);
    std::vector<int> b(edges.size(), -1);  // 経路復元
    using Pi = std::pair<Info, int>;

    std::priority_queue<Pi, std::vector<Pi>, std::greater<Pi>> que;
    dist[s] = 0;
    que.emplace(dist[s], s);
    while(!que.empty()) {
        Info cost;
        int idx;
        std::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;
    scanf("%ld%ld", &N, &M);
    edamat::directed_graph<i64> g(3 * N);
    while(M--) {
        i64 u, v;
        scanf("%ld%ld", &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;
    scanf("%ld%ld", &S, &T);
    S--, T--;
    // BFS
    // auto dist = g.bfs(S);
    // dijkstra
    auto dist = g.dijkstra(S);
    printf("%ld\n",
           (dist[T] == std::numeric_limits<i64>::max() ? -1 : dist[T] / 3));
};

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

Measured memory_bytes: 20224