#include <algorithm>
#include <bits/stdc++.h>
#include <cassert>
#include <cstddef>
#include <cstdint>
#include <functional>
#include <iostream>
#include <iterator>
#include <limits>
#include <queue>
#include <vector>

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


typedef ::std::int_fast64_t i64;
typedef ::std::uint_fast64_t u64;
typedef ::std::int_fast32_t i32;
typedef ::std::uint_fast32_t u32;

namespace tools {
  template <typename T>
  void read(::std::istream& is, ::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    vector.reserve(size);
    ::std::copy_n(::std::istream_iterator<T>(is), size, ::std::back_inserter(vector));
  }
  template <typename T>
  void read(::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    ::tools::read(::std::cin, vector, size);
  }

  template <typename T, ::std::size_t N>
  void read(::std::istream& is, ::std::array<T, N>& array) {
    ::std::copy_n(std::istream_iterator<T>(is), N, array.begin());
  }
  template <typename T, ::std::size_t N>
  void read(::std::array<T, N>& array) {
    ::tools::read(::std::cin, array);
  }
}

#endif

// lib/dijkstra.hpp
#ifndef DIJKSTRA_HPP
#define DIJKSTRA_HPP


/*
usage:

tools::dijkstra<std::int_fast64_t> dijkstra(node_count);
dijkstra.add_edge(from_node, to_node, cost);
const tools::dijkstra<std::int_fast64_t>::result result = dijkstra.calc(start_node);
for (const std::int_fast64_t& distance : result.distances) {
  // ...
}
*/

namespace tools {
  template <typename T>
  class dijkstra {
  private:
    class edge {
    public:
      std::size_t from;
      std::size_t to;
      T distance;
      edge(const std::size_t from, const std::size_t to, const T distance) :
        from(from),
        to(to),
        distance(distance) {
      }
    };

    class task {
    public:
      std::size_t vertex;
      T distance;
      task(const std::size_t vertex, const std::size_t distance) :
        vertex(vertex), distance(distance) {
      }
    };

    std::vector<std::vector<edge>> edges;

  public:
    static constexpr T INF = std::numeric_limits<T>::max();
    static constexpr std::size_t NONE = std::numeric_limits<std::size_t>::max();

    class result {
    public:
      std::vector<T> distances;
      std::vector<std::size_t> prev_nodes;
      result(const std::size_t node_count, const std::size_t start_node) :
        distances(node_count, INF),
        prev_nodes(node_count, NONE) {
        this->distances[start_node] = 0;
      }
    };

    dijkstra(const std::size_t node_count) :
      edges(node_count) {
    }

    std::size_t node_count() const {
      return this->edges.size();
    }

    void add_edge(const std::size_t from, const std::size_t to, const T distance) {
      this->edges[from].emplace_back(from, to, distance);
    }

    result calc(const std::size_t start_node) const {
      assert(start_node < this->node_count());

      result result(this->node_count(), start_node);
      std::vector<bool> visited(this->node_count(), false);
      std::priority_queue<task, std::vector<task>, std::function<bool(task, task)>> tasks([](const task& x, const task& y) {
        return x.distance > y.distance;
      });
      tasks.emplace(start_node, 0);

      while (!tasks.empty()) {
        const task task = tasks.top();
        tasks.pop();
        if (visited[task.vertex]) continue;
        visited[task.vertex] = true;
        for (const edge& edge : this->edges[task.vertex]) {
          const T new_distance = task.distance + edge.distance;
          if (new_distance < result.distances[edge.to]) {
            result.distances[edge.to] = new_distance;
            result.prev_nodes[edge.to] = edge.from;
            tasks.emplace(edge.to, new_distance);
          }
        }
      }

      return result;
    }
  };
}

#endif

// main.cpp

int main() {
  i64 N, M;
  std::cin >> N >> M;

  tools::dijkstra<i64> dijkstra(3 * N);
  for (i64 i = 0; i < M; ++i) {
    i64 u_i, v_i;
    std::cin >> u_i >> v_i;
    --u_i;
    --v_i;
    dijkstra.add_edge(u_i, N + v_i, 1);
    dijkstra.add_edge(N + u_i, 2 * N + v_i, 1);
    dijkstra.add_edge(2 * N + u_i, v_i, 1);
  }

  i64 S, T;
  std::cin >> S >> T;
  --S;
  --T;

  const auto result = dijkstra.calc(S);
  std::cout << (result.distances[T] == std::numeric_limits<i64>::max() ? -1 : result.distances[T] / 3) << std::endl;
  return 0;
}

Measured memory_bytes: 21376