// Original C++ solution (slower):
#include <iostream>

#include <string>

#include <algorithm>

#include <vector>

#include <math.h>

#include <complex>

#include <queue>

#include <deque>

#include <stack>

#include <map>

#include <set>

#include <bitset>

#include <assert.h>

#include <numeric>

#include <iomanip>

#define rep(i, a, b) for (int(i) = (a); i < (b); i++)

using namespace std;



using ll = long long;



typedef pair<int, int> P;



const int INF = 100000000;

const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

const ll MOD = 1000000007;



ll pow_mod(ll x, ll y, ll mod)

{

	ll ans=1;

	for(;y>0;y>>=1){

		if(y&1)(ans*=x)%=mod;

		(x*=x)%=mod;

	}

	return ans;

}



ll n, m;

ll s , t;

int d[300000];



vector<int> vv[300000];



void dijkstra(int s)

{

	priority_queue<P, vector<P>, greater<P>> que;

	fill(d, d + 3 * n, INF);

	d[s] = 0;

	que.push(P(0, s));



	while (!que.empty())

	{

		P p = que.top();

		que.pop();

		int v = p.second;

		if(d[v]<p.first){

			continue;

		}

		for (int i = 0; i < vv[v].size();i++){

			int u = vv[v][i];

			if(d[u]>d[v]+1){

				d[u] = d[v] + 1;

				que.push(P(d[u], u));

			}

		}

	}

}



int main()

{

	cin.tie(0);

	ios::sync_with_stdio(false);

	//問題文中の添え字が0-indexか1-indexか確認!

	cin >> n >> m;



	rep(i,0,m){

		int a, b;

		cin >> a >> b;

		a--;

		b--;

		vv[a].push_back(n + b);

		vv[n + a].push_back(n * 2 + b);

		vv[n * 2 + a].push_back(b);

	}



	cin >> s >> t;

	s--;

	t--;



	dijkstra(s);

	if(d[t]!=INF){

		cout << d[t]/3;

	}else{

		cout << -1;

	}

	return 0;

}

// Optimized solution to the same problem (faster):
#include <assert.h>

#include <limits.h>

#include <algorithm>

#include <bitset>

#include <cctype>

#include <cmath>

#include <complex>

#include <deque>

#include <functional>

#include <iomanip>

#include <iostream>

#include <map>

#include <numeric>

#include <queue>

#include <set>

#include <stack>

#include <string>

#include <unordered_map>

#include <vector>

 

using ll = long long;

using P = std::pair<long double, ll>;

 

#define rep(i, a, b) for (ll(i) = (a); i < (b); i++)

#define all(i) i.begin(), i.end()

#define debug(i) std::cerr << "debug " << #i <<" "<<i<< std::endl

 

template <typename T1, typename T2>

std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {

  return os << pa.first << " " << pa.second;

}

 

template <typename T>

std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {

  for (int i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");

  return os;

}

 

template<typename T1,typename T2>

inline bool chmax(T1& a,T2 b){return a<b && (a=b,true);}

 

template<typename T1,typename T2>

inline bool chmin(T1& a,T2 b){return a>b && (a=b,true);}

 

// const ll MOD = 998244353;

const ll MOD = 1e9 + 7;





 

int main() {

  std::cin.tie(0);

  std::ios::sync_with_stdio(false);



  ll n,m;

  std::cin>>n>>m;



  std::vector<std::vector<ll>> graph(3*n);



  rep(i,0,m){

    ll u,v;

    std::cin>>u>>v;

    u--;v--;



    rep(j,0,3)graph[u+n*j].push_back((v+n*((j+1)%3)));

  }



  std::vector<bool> used(3*n,false);



  ll s,t;

  std::cin>>s>>t;



  s--;t--;



  std::queue<P> que;



  used[s]=true;

  que.push({s,0});



  while(!que.empty()){

    P e=que.front();que.pop();



    if(e.first==t){

      std::cout<<e.second/3;

      return 0;

    }



    for(ll next:graph[e.first]){

      if(!used[next]){

        used[next]=true;

        que.push({next,e.second+1});

      }

    }

  }



  std::cout<<-1;



  return 0;

}








// Fastest known solution for this problem: