#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define uniq(v) v.erase(unique(v.begin(),v.end()),v.end())
#define lb(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define ub(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
using Pair = pair<ll,pair<int,int>>;
#define pq priority_queue<Pair, vector<Pair>, greater<Pair>> 
const ll mod=1000000007;
//const ll mod=998244353;
const ld pi=acos(-1.0);
const ll INF = 1LL<<61;
template<class T>bool chmax(T &a, const T &b) { 
  if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) {
  if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる


//——————————————————matrix　行列———————————————————————————


template< class T >
struct Mat {
    std::vector< std::vector< T > > A;
    Mat() {}
    Mat(size_t n, size_t m) : A(n, std::vector< T >(m, 0)) {}
    Mat(size_t n) : A(n, std::vector< T >(n, 0)) {};
    size_t height() const {
        return (A.size());
    }
    size_t width() const {
        return (A[0].size());
    }
    inline const std::vector< T > &operator[](int k) const {
        return (A.at(k));
    }
    inline std::vector< T > &operator[](int k) {
        return (A.at(k));
    }
    static Mat I(size_t n) {
        Mat mat(n);
        for (int i = 0; i < n; i++) mat[i][i] = 1;
        return (mat);
    }
    Mat &operator+=(const Mat &B) {
        size_t n = height(), m = width();
        assert(n == B.height() && m == B.width());
        for (int i = 0; i < n; i++)
            for (int j = 0; j < m; j++)
                (*this)[i][j] += B[i][j];
        return (*this);
    }
    Mat &operator-=(const Mat &B) {
        size_t n = height(), m = width();
        assert(n == B.height() && m == B.width());
        for (int i = 0; i < n; i++)
            for (int j = 0; j < m; j++)
                (*this)[i][j] -= B[i][j];
        return (*this);
    }
    Mat &operator*=(const Mat &B) {
        size_t n = height(), m = B.width(), p = width();
        assert(p == B.height());
        std::vector< std::vector< T > > C(n, std::vector< T >(m, 0));
        for (int i = 0; i < n; i++)
            for (int j = 0; j < m; j++)
                for (int k = 0; k < p; k++)
                    C[i][j] = (C[i][j] + (*this)[i][k] * B[k][j]);
        A.swap(C);
        return (*this);
    }
    Mat operator+(const Mat &B) const {
        return (Mat(*this) += B);
    }
    Mat operator-(const Mat &B) const {
        return (Mat(*this) -= B);
    }
    Mat operator*(const Mat &B) const {
        return (Mat(*this) *= B);
    }
    friend std::ostream &operator<<(std::ostream &os, Mat &p) {
        size_t n = p.height(), m = p.width();
        for (int i = 0; i < n; i++) {
            os << "[";
            for (int j = 0; j < m; j++) {
                os << p[i][j] << (j + 1 == m ? "]\n" : ",");
            }
        }
        return (os);
    }
    
    T determinant() {
        Mat B(*this);
        assert(width() == height());
        T ret = 1;
        for (int i = 0; i < width(); i++) {
            int idx = -1;
            for (int j = i; j < width(); j++) {
                if (B[j][i] != 0) idx = j;
            }
            if (idx == -1) return (0);
            if (i != idx) {
                ret *= -1;
                swap(B[i], B[idx]);
            }
            ret *= B[i][i];
            T vv = B[i][i];
            for (int j = 0; j < width(); j++) {
                B[i][j] /= vv;
            }
            for (int j = i + 1; j < width(); j++) {
                T a = B[j][i];
                for (int k = 0; k < width(); k++) {
                    B[j][k] -= B[i][k] * a;
                }
            }
        }
        return (ret);
    }
    
    
    Mat pow(int64_t k) const {
        auto res = I(A.size());
        auto M = *this;
        while (k > 0) {
            if (k & 1) {
                res *= M;
            }
            M *= M;
            k >>= 1;
        }
        return res;
    }
};



//—————————————————————————————————————————————————


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

  int n,m;
  cin>>n>>m;

  vector<vector<int>> g(3*n);
  rep(i,m){
    int a,a2,a3,b,b2,b3;
    cin>>a>>b;
    a--;b--;
    a2=(a+n)%(3*n);
    a3=(a+2*n)%(3*n);
    b2=(b+n)%(3*n);
    b3=(b+2*n)%(3*n);
    g[a].pb(b2);
    g[a2].pb(b3);
    g[a3].pb(b);
  }

  int st,go;
  cin>>st>>go;
  st--;go--;

  vector<int> dist(3*n,-1);
  deque<int> que;

  dist[st]=0;
  que.pb(st);

  while(!que.empty()){
    int v=que.front();
    que.pop_front();
    for(int nv : g[v]){
      if(dist[nv]!=-1) continue;
      dist[nv]=dist[v]+1;
      que.pb(nv);
    }
  }

  if(dist[go]==-1) cout << -1 << endl;
  else cout << dist[go]/3 << endl;
}

Measured memory_bytes: 20812