/*~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
*$* WRITER:kakitamasziru/OxOmisosiru *$*
~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=*/
#ifdef LOCAL_JUDGE
#define _GLIBCXX_DEBUG
#endif
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <iomanip>
#include <limits>//setprecision
//#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
//#include <unordered_set> //unordered_set
#include <stack> // stack
#include <deque> // deque
#include <math.h>//pow,,,
#include <cmath>//abs,,,
#include <bitset> // bitset
#define endl "\n";
using namespace std;

const long long INF = 4000000000000000001;
const int inf = 1001001001;
const int MOD = 1000000007;
typedef pair<long long,long long> P;

void chmax(long long &a,long long b){if(a < b) a = b;}
void chmin(long long &a,long long b){if(a > b) a = b;}

//Solve N^M. This, mod_pow use Iterative Square Method.
long long mod_pow(long long N, long long M) {
    if (M == 0) return 1;
    long long res = mod_pow((N * N) % MOD, M / 2);
    //When end-of-a bit is 1, times simple N.
    if (M & 1) res = (res * N) % MOD;
    return res %= MOD;
}
long long gcd(long long a, long long b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}
long long lcm(long long a, long long b) {
    return a / gcd(a, b) * b ;
}

vector<vector<int>> Edge_remain2_0(100005);
vector<vector<int>> Edge_remain0_1(100005);
vector<vector<int>> Edge_remain1_2(100005);

int main() {
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    
    int N;cin >> N;
    int M;cin >> M;
    for(int i = 0;i<M;i++){
        int from,to;cin >> from >> to;from--;to--;
        Edge_remain2_0.at(from).push_back(to);
        Edge_remain0_1.at(from).push_back(to);
        Edge_remain1_2.at(from).push_back(to);
    }
    int start,goal;cin >> start >> goal;start--;goal--;
    queue<pair<pair<int,int>,int>> Q;
    Q.push(make_pair(make_pair(start,0),0));
    vector<vector<bool>> seen(3,vector<bool>(N));
    seen.at(2).at(start) = true;
    while(!Q.empty()){
        pair<pair<int,int>,int> P = Q.front();Q.pop();
        int from = P.first.first,remainder = P.first.second,dist = P.second;
        //cout << from << " " << remainder << " " << dist << endl;
        remainder %= 3;
        if(from == goal && remainder == 0){
            cout << dist/3 << endl;
            return 0;
        }
        if(remainder == 0){
            for(int to : Edge_remain0_1.at(from)){
                if(seen.at(0).at(to)) continue;
                seen.at(0).at(to) = true;
                Q.push(make_pair(make_pair(to,remainder+1),dist+1));
            }
        }
        if(remainder == 1){
            for(int to : Edge_remain1_2.at(from)){
                if(seen.at(1).at(to)) continue;
                seen.at(1).at(to) = true;
                Q.push(make_pair(make_pair(to,remainder+1),dist+1));
            }
        }
        if(remainder == 2){
            for(int to : Edge_remain2_0.at(from)){
                if(seen.at(2).at(to)) continue;
                seen.at(2).at(to) = true;
                Q.push(make_pair(make_pair(to,remainder+1),dist+1));
            }
        }
    }
    cout << -1 << endl;
}

Measured memory_bytes: 19556