#include <bits/stdc++.h>

#define REP(i, n) for(decltype(n) i = 0; i < n; i++)

#define INF  (int)1e9
#define LINF (long long)1e18

#define ALL(c)   c.begin(), c.end()
#define SORT(c)  std::sort(ALL(c))
#define RSORT(c) std::sort(ALL(c), std::greater<decltype(c)::value_type>())

using namespace std;
using ll = long long;

class Graph {
public:
    struct Edge {
        int       src, dst;
        long long cost, capacity, flow;
        size_t    rev;
        Edge(const int&       _src,
             const int&       _dst,
             const long long& _cost     = 0,
             const long long& _capacity = 0,
             const long long& _frow     = 0,
             const size_t&    _rev      = 0) :
            src(_src),
            dst(_dst),
            cost(_cost),
            capacity(_capacity),
            flow(_frow),
            rev(_rev) { }
    };

    struct Vertex {
        long long cost;
        Vertex(const long long& _cost) :
            cost(_cost) { }
    };

    enum class Type {
        Directed,
        Undirected,
    };

    std::vector<Vertex>            vertex;
    std::vector<std::vector<Edge>> edge;

    Graph(const int&  num_vertex,
          const Type& _type) :
        vertex(num_vertex, 0),
        edge(num_vertex),
        type_(_type) { }

    void addEdge(const int&        src,
                 const int&        dst,
                 const long long&  cost,
                 const long long&  capacity = 0) {
        switch(type_) {
            case Type::Directed: {
                edge[src].emplace_back(src, dst, cost,  capacity, 0, edge[dst].size());
                edge[dst].emplace_back(dst, src, -cost,        0, 0, edge[src].size() - 1);
                break;
            }
            case Type::Undirected: {
                edge[src].emplace_back(src, dst, cost);
                edge[dst].emplace_back(dst, src, cost);
                break;
            }
        }
    }

    // 最大流問題を解く
    // Dinic's blocking flow
    long long calcMaxFlow(const int& src_index,
                          const int& sink_index) {
        if(type_ != Type::Directed) {
            throw std::logic_error("Graph type is invalid");
        }
        std::vector<int> level(vertex.size()), iter(vertex.size());
        std::function<int(void)> levelize
            = [&]() {
                  level.assign(vertex.size(), -1);
                  level[src_index] = 0;
                  queue<int> Q;
                  Q.push(src_index);
                  while(!Q.empty()) {
                      int u = Q.front();
                      Q.pop();
                      if(u == sink_index) {
                          break;
                      }
                      for(const auto& e : edge[u]) {
                          if(e.flow < e.capacity && level[e.dst] < 0) {
                              Q.push(e.dst);
                              level[e.dst] = level[u] + 1;
                          }
                      }
                  }
                  return level[sink_index];
              };
        function<long long(int, long long)> augment
            = [&](int u, long long cur) {
                  if(u == sink_index) {
                      return cur;
                  }
                  for(size_t i = iter[u]; i < edge[u].size(); ++i) {
                      auto& e = edge[u][i];
                      auto& r = edge[e.dst][e.rev];
                      if(e.flow < e.capacity && level[u] < level[e.dst]) {
                          auto f = augment(e.dst, min(cur, e.capacity - e.flow));
                          if(0 < f) {
                              e.flow += f;
                              r.flow -= f;
                              return f;
                          }
                      }
                  }
                  return 0LL;
              };
        for(auto& v : edge) {
            for(auto &e : v) {
                e.flow = 0;
            }
        }
        auto flow = 0LL;
        while(0 <= levelize()) {
            std::fill(iter.begin(), iter.end(), 0);
            for(long long f; 0 < (f = augment(src_index, INF)); flow += f);
        }
        return flow;
    }

    // 幅優先探索で最小コストを求める
    bool calcMinCostByBFS(long long& min_cost,
                          const int& start_index,
                          const int& goal_index) {
        std::fill(vertex.begin(), vertex.end(), std::numeric_limits<long long>::max());
        vertex[start_index] = 0;
        queue<int> queue;
        queue.push(start_index);
        while(!queue.empty()) {
            const auto src = queue.front();
            queue.pop();
            for(const auto& v : edge[src]) {
                if(v.cost < 0) {
                    continue;
                }
                const auto& dst  = v.dst;
                const auto  cost = vertex[src].cost + v.cost;
                if(cost < vertex[dst].cost) {
                    vertex[dst] = cost;
                    queue.push(dst);
                }
            }
        }
        min_cost = vertex[goal_index].cost;
        return (min_cost == std::numeric_limits<long long>::max()) ? false : true;
    }

private:
    const Type type_;
};

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

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

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

    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;

    ll min_cost;
    std::cout << (g.calcMinCostByBFS(min_cost, start, goal) ? min_cost / 3 : -1) << std::endl;

    return 0;
}


Measured memory_bytes: 40448