#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <iomanip>
#include <limits>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <tuple>
#include <deque>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <utility>
#include <complex>
#include <functional>
using namespace std;
const int MOD = 1000000007;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = (1 << 28);
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
//setprecision(15)有効数字15桁
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b)
{
    return a * b / gcd(a, b);
}
struct edge {
    int to, cost;
};
int n;
template<typename T> class bellman_ford {
public:
	struct edge{
		int from,to;
		T cost;
	};
	vector<int> d;
	vector<edge> es;
	int edge_id;
	int V,E;
	bellman_ford(int node_size){
		edge_id = 0, V = node_size;
		d.resize(node_size,numeric_limits<T>::max());
	}
	void add_edge(int from,int to,T cost){
		es.push_back((edge){from,to,cost});
	}
	//sからの最短路長およびsからたどり着ける負の閉路の検出(trueなら負の閉路が存在する)
	bool solve(int s){
		E = (int)es.size();
		int cnt = 0;
		d[s] = 0;
		while(cnt < V){
			bool update = false;
			rep(i,E){
				edge e = es[i];
				if(d[e.from] != numeric_limits<T>::max() && d[e.to] > d[e.from] + e.cost){
					d[e.to] = d[e.from] + e.cost;
					update = true;
				}
			}
			if(!update) break;
			cnt++;
		}
		return (cnt == V);
	}
	//すべての負の閉路の検出(trueなら負の閉路が存在する)
	bool find_negative_loop(){
		E = (int)es.size();
	    fill(d.begin(),d.end(),0);
		int cnt = 0;
		while(cnt < V){
 		   bool update = false;
 		   rep(i,E){
 			   edge e = es[i];
 			   if(d[e.to] > d[e.from] + e.cost){
 				   d[e.to] = d[e.from] + e.cost;
 				   update = true;
 			   }
 		   }
 		   if(!update) break;
 		   cnt++;
 	   }
 	   return (cnt == V);
	}
	//sからtへの最短路上に存在する負の閉路の検出(trueなら負の閉路が存在する)
	bool find_negative_loop(int s,int t){
		E = (int)es.size();
		d[s] = 0;
		rep(i,2*V){
			rep(j,E){
				edge e = es[j];
				if(d[e.from] != numeric_limits<T>::max() && d[e.to] > d[e.from] + e.cost){
					d[e.to] = d[e.from] + e.cost;
					if(i >= V-1 && e.to == t){
						return true;
					}
				}
			}
		}
		return false;
	}
};
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int m;
    cin >> n>>m;
    bellman_ford<int> g(3*n);
    for (int i = 0; i < m; i++)
    {
        int in, out;
        cin >> in>>out;
        in--;
        out--;
        g.add_edge(in,out+n,1);
        g.add_edge(in+n,out+n*2,1);
        g.add_edge(in+2*n,out,1);
    }
    int s, t;
    cin>>s>>t;
    s--;
    t--;
    g.solve(s);
    if(g.d[t]==numeric_limits<int>::max()){
        cout<<-1<<"\n";
        return 0;
    }
    cout <<g.d[t]/3  << "\n";
}


Measured memory_bytes: 9712