#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")

#include "bits/stdc++.h"
using namespace std;

#define pb push_back
#define F first
#define S second
#define f(i,a,b)  for(int i = a; i < b; i++)
// #define endl '\n'

using ll = long long;
using db = long double;
using ii = pair<int, int>;

const int N = 1e5+5, LG = 17, MOD = 998244353;
const int SQ = 450;
const long double EPS = 1e-7;
int n, m;
vector<int> adj[N];
int vis[N][3];
int32_t main(){
#ifdef ONLINE_JUDGE
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#endif

  cin >> n >> m;

  f(i,0,m){
    int u, v;
    cin>>u>>v;
    adj[u].pb(v);
  }

  int s,t;
  cin>>s>>t;
  memset(vis,-1,sizeof vis);
  queue<ii>q({ii(s,0)});
  vis[s][0]=0;
  while(q.size()){
    auto cur=q.front(); q.pop();
    for(auto v:adj[cur.F])
    if(vis[v][(cur.S+1)%3]==-1){
      vis[v][(cur.S+1)%3] = vis[cur.F][cur.S] + 1;
      q.push(ii(v,(cur.S+1)%3));
    }
  }
  if(vis[t][0]!=-1)vis[t][0]/=3;
  cout<<vis[t][0]<<endl;

  return 0;
}
