stablegradients/pie-gem5-bysrc huggingface dataset:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

const ll MAXN=2e5+5;

const ll MOD=1e9+7;

const ll INF=1e18;

ll n,m,s,t,vis1[MAXN],vis2[MAXN],vis3[MAXN];

vector<ll>G[MAXN];

void solve()

{

    queue<pair<ll,ll> >q;

    q.push(make_pair(s,0));

    while(!q.empty())

    {

        pair<ll,ll> up=q.front();

        ll u=up.first,step=up.second;

        if(u==t)

        {

            printf("%lld\n",step);

            return;

        }

        q.pop();

        for(ll i=0;i<G[u].size();i++)

        {

            ll v1=G[u][i];

            if(vis1[v1])continue;

            vis1[v1]=1;

            for(ll j=0;j<G[v1].size();j++)

            {

                ll v2=G[v1][j];

                if(vis2[v2])continue;

                vis2[v2]=1;

                for(ll k=0;k<G[v2].size();k++)

                {

                    ll v3=G[v2][k];

                    if(vis3[v3])continue;

                    q.push(make_pair(v3,step+1));

                    vis3[v3]=1;

                }

            }

        }

    }

    printf("-1\n");

}

int main()

{

//    freopen("c://duipai//data.txt","r",stdin);

//    freopen("c://duipai//wa.txt","w",stdout);

    while(~scanf("%lld %lld",&n,&m))

    {

//        string ss;

//        cin>>ss;

//        cout<<ss<<endl;

       for(ll i=1;i<=m;i++)

       {

           ll u,v;

           scanf("%lld %lld",&u,&v);

           G[u].push_back(v);

       }

       scanf("%lld %lld",&s,&t);

       solve();

    }

}

/*

5

76578820211343624  293297008968192 189152283861189120 324294649604739072 20266198324215808

*/


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

using namespace std;

#define ld long double

#define ll long long

#define pb push_back

#define F first

#define S second

const int mod = 1e9+7, A = 4e4+5;

int n, m;

vector<vector<int>> v;

int bfs(int src, int dst)

{

    int ans[n + 1][3];

    for (int i = 0; i <= n; i++)

        for (int j = 0; j < 3; j++)

            ans[i][j] = 1e9;

    queue<pair<int, int>> q;

    q.push({src, 0});

    ans[src][0] = 0;

    while(!q.empty())

    {

        int node = q.front().F, md = q.front().S;

        q.pop();

        for (auto to : v[node])

        {

            int nxt_md = (md + 1) % 3;

            if (ans[to][nxt_md] == 1e9)

            {

                q.push({to, nxt_md});

                ans[to][nxt_md] = ans[node][md] + 1;

            }

        }

    }

    return (ans[dst][0] == 1e9 ? -1 : ans[dst][0] / 3);

}

int main()

{

    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);

    cin >> n >> m;

    v.resize(n + 1);

    for (int i = 0; i < m; i++)

    {

        int x, y;

        cin >> x >> y;

        v[x].pb(y);

    }

    int s, t;

    cin >> s >> t;

    cout << bfs(s, t);

    return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>



using namespace std;

const int N = 1e5 + 5;

int head[N], nxt[N * 2], to[N * 2], ne = 0;



void addedge(int a, int b) {

    nxt[ne] = head[a];

    to[ne] = b;

    head[a] = ne++;

}



int dist[N][4];

int a, b;



int bfs(int s) {

    memset(dist, '?', sizeof dist);

    dist[s][0] = 0;

    queue<pair<int, int>> q;

    q.push({s, 0});

    while (q.size()) {

        int u = q.front().first, l = q.front().second;

        q.pop();

        int lv = dist[u][l];

        if (u == b && l == 0) return lv / 3;

        for (int i = head[u]; ~i; i = nxt[i]) {

            int v = to[i], vl = (l + 1) % 3;

            if (dist[v][vl] > lv + 1) {

                dist[v][vl] = lv + 1;

                q.push({v, vl});

            }

        }

    }

    return -1;

}



int main() {

 //   freopen("in.txt", "rt", stdin);

    int n, m;

    memset(head, -1, sizeof head);

    scanf("%d %d", &n, &m);

    while (m--) {

        scanf("%d %d", &a, &b);

        addedge(a, b);

    }

    scanf("%d %d", &a, &b);

    printf("%d\n", bfs(a));

}

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

using namespace std;

#define ld long double

#define ll long long

#define pb push_back

#define F first

#define S second

const int mod = 1e9+7, A = 4e4+5;

int n, m;

vector<vector<int>> v;

int bfs(int src, int dst)

{

    int ans[n + 1][3];

    for (int i = 0; i <= n; i++)

        for (int j = 0; j < 3; j++)

            ans[i][j] = 1e9;

    queue<pair<int, int>> q;

    q.push({src, 0});

    ans[src][0] = 0;

    while(!q.empty())

    {

        int node = q.front().F, md = q.front().S;

        q.pop();

        for (auto to : v[node])

        {

            int nxt_md = (md + 1) % 3;

            if (ans[to][nxt_md] == 1e9)

            {

                q.push({to, nxt_md});

                ans[to][nxt_md] = ans[node][md] + 1;

            }

        }

    }

    return (ans[dst][0] == 1e9 ? -1 : ans[dst][0] / 3);

}

int main()

{

    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);

    cin >> n >> m;

    v.resize(n + 1);

    for (int i = 0; i < m; i++)

    {

        int x, y;

        cin >> x >> y;

        v[x].pb(y);

    }

    int s, t;

    cin >> s >> t;

    cout << bfs(s, t);

    return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

const int N = 1e5 + 10;

vector<int> a[N];

int b[N][3];

int main()

{

	ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);

	int n, m;

	cin >> n >> m;

	for (int i = 0; i < m; i++)

	{

		int u, v;

		cin >> u >> v;

		a[u].push_back(v);

	}

	for (int i = 1; i <= n; i++)

	{

		for (int j = 0; j < 3; j++)

		{

			b[i][j] = -3;

		}

	}

	int s, t;

	cin >> s >> t;

	queue <pair< int, int >> q;

	b[s][0] = 0;

	q.push({ s,0 });

	while (!q.empty())

	{

		const int cx = q.front().first, cy = q.front().second, ny = (cy + 1) % 3;

		q.pop();

		for (int i = 0; i<int(a[cx].size()); i++)

		{

			const int nx = a[cx][i];

			if (b[nx][ny] == -3)

			{

				q.push({ nx,ny });

				b[nx][ny] = b[cx][cy] + 1;

			}

		}

	}

	cout << b[t][0]/3 << endl;





}


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

using namespace std;

#define ld long double

#define ll long long

#define pb push_back

#define F first

#define S second

const int mod = 1e9+7, A = 4e4+5;

int n, m;

vector<vector<int>> v;

int bfs(int src, int dst)

{

    int ans[n + 1][3];

    for (int i = 0; i <= n; i++)

        for (int j = 0; j < 3; j++)

            ans[i][j] = 1e9;

    queue<pair<int, int>> q;

    q.push({src, 0});

    ans[src][0] = 0;

    while(!q.empty())

    {

        int node = q.front().F, md = q.front().S;

        q.pop();

        for (auto to : v[node])

        {

            int nxt_md = (md + 1) % 3;

            if (ans[to][nxt_md] == 1e9)

            {

                q.push({to, nxt_md});

                ans[to][nxt_md] = ans[node][md] + 1;

            }

        }

    }

    return (ans[dst][0] == 1e9 ? -1 : ans[dst][0] / 3);

}

int main()

{

    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);

    cin >> n >> m;

    v.resize(n + 1);

    for (int i = 0; i < m; i++)

    {

        int x, y;

        cin >> x >> y;

        v[x].pb(y);

    }

    int s, t;

    cin >> s >> t;

    cout << bfs(s, t);

    return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N=1e5+5;



#define endl "\n"



bool vis[N][3];

vector<int> G[N];

int n,m,S,T;



struct node{

	int now,t;

};



void bfs(){

	node p,q;

	p.now=S;

	p.t=0;

	vis[p.now][p.t]=1;

	queue<node> Q;

	Q.push(p);

	while(!Q.empty()){

		q=Q.front();

		Q.pop();

		if(q.now==T&&q.t%3==0) {

			cout<<q.t/3<<endl;

			return;

		}

		int t=(q.t+1)%3,v=q.now,u;

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

			u=G[v][i];

			if(!vis[u][t]){

				vis[u][t]=1;

				p.now=u;

				p.t=q.t+1;

				Q.push(p);

			}

		}

	}

	cout<<-1<<endl;

}



int main(){

	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);

	cin>>n>>m;

	memset(vis,0,sizeof(vis));

	int v,u;

	while(m--){

		cin>>v>>u;

		G[v].push_back(u);

	}

	cin>>S>>T;

	bfs();

	return 0;

}

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

using namespace std;

#define ld long double

#define ll long long

#define pb push_back

#define F first

#define S second

const int mod = 1e9+7, A = 4e4+5;

int n, m;

vector<vector<int>> v;

int bfs(int src, int dst)

{

    int ans[n + 1][3];

    for (int i = 0; i <= n; i++)

        for (int j = 0; j < 3; j++)

            ans[i][j] = 1e9;

    queue<pair<int, int>> q;

    q.push({src, 0});

    ans[src][0] = 0;

    while(!q.empty())

    {

        int node = q.front().F, md = q.front().S;

        q.pop();

        for (auto to : v[node])

        {

            int nxt_md = (md + 1) % 3;

            if (ans[to][nxt_md] == 1e9)

            {

                q.push({to, nxt_md});

                ans[to][nxt_md] = ans[node][md] + 1;

            }

        }

    }

    return (ans[dst][0] == 1e9 ? -1 : ans[dst][0] / 3);

}

int main()

{

    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);

    cin >> n >> m;

    v.resize(n + 1);

    for (int i = 0; i < m; i++)

    {

        int x, y;

        cin >> x >> y;

        v[x].pb(y);

    }

    int s, t;

    cin >> s >> t;

    cout << bfs(s, t);

    return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

#define rep(i, n) for(int i = 0; i < (n); i++)

#define rep1(i, n) for(int i = 1; i <= (n); i++)

#define co(x) cout << (x) << "\n"

#define cosp(x) cout << (x) << " "

#define ce(x) cerr << (x) << "\n"

#define cesp(x) cerr << (x) << " "

#define pb push_back

#define mp make_pair

#define Would

#define you

#define please



#define PT pair<int, int>



int main() {

	cin.tie(0);

	ios::sync_with_stdio(false);





	int N, M;

	cin >> N >> M;

	int to[100001], ne[100001], he[100001] = {};

	rep1(i, M) {

		int u, v;

		cin >> u >> v;

		to[i] = v;

		ne[i] = he[u];

		he[u] = i;

	}

	int S, T;

	cin >> S >> T;



	int D[300004];

	rep(i, 300004) D[i] = 1e9;

	D[3 * S] = 0;



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

	que.push(mp(0, 3 * S));

	while (que.size()) {

		PT p = que.top();

		que.pop();

		int i = p.second;

		if (D[i] != p.first) continue;

		int i2 = i / 3;

		for (int j = he[i2]; j; j = ne[j]) {

			int d = D[i] + 1;

			int j2 = to[j] * 3 + (i + 1) % 3;

			if (D[j2] > d) {

				D[j2] = d;

				que.push(mp(d, j2));

			}

		}

	}



	if (D[3 * T] == 1e9) co(-1);

	else co(D[3 * T] / 3);



	Would you please return 0;

}

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

#include<cstdio>

using namespace std;

typedef long long ll;

#define rep(i, n) for(int i = 0; i < (n); i++)

#define rep1(i, n) for(int i = 1; i <= (n); i++)

#define co(x) cout << (x) << "\n"

#define cosp(x) cout << (x) << " "

#define ce(x) cerr << (x) << "\n"

#define cesp(x) cerr << (x) << " "

#define pb push_back

#define mp make_pair

#define Would

#define you

#define please



const int cm = 1 << 17;

char cn[cm], * ci = cn + cm;

inline char getcha() {

	if (ci - cn == cm) { fread(cn, 1, cm, stdin); ci = cn; }

	return *ci++;

}

inline int getint() {

	char C = getcha();

	int A = C - '0';

	while ((C = getcha()) >= '0') A = A * 10 + C - '0';

	return A;

}



int main() {

	//cin.tie(0);

	//ios::sync_with_stdio(false);





	int N = getint(), M = getint();

	int to[100001], ne[100001], he[100001] = {};

	rep1(i, M) {

		int u = getint();

		to[i] = getint();

		ne[i] = he[u];

		he[u] = i;

	}

	int S = getint(), T = getint();



	int D[300004];

	rep(i, 300004) D[i] = 1e9;

	D[3 * S] = 0;



	int q[300000];

	int k1 = 0;

	int k2 = 1;

	q[0] = 3 * S;

	for (int k1 = 0; k1 < k2; k1++) {

		int i = q[k1];

		int i2 = i / 3;

		int d = D[i] + 1;

		for (int j = he[i2]; j; j = ne[j]) {

			int j2 = to[j] * 3 + (i + 1) % 3;

			if (D[j2] > d) {

				D[j2] = d;

				q[k2++] = j2;

			}

		}

	}



	if (D[3 * T] == 1e9) printf("-1");

	else printf("%d", D[3 * T] / 3);



	Would you please return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

#define rep(i, n) for(int i = 0; i < (n); i++)

#define rep1(i, n) for(int i = 1; i <= (n); i++)

#define co(x) cout << (x) << "\n"

#define cosp(x) cout << (x) << " "

#define ce(x) cerr << (x) << "\n"

#define cesp(x) cerr << (x) << " "

#define pb push_back

#define mp make_pair

#define Would

#define you

#define please



#define PT pair<int, int>



int main() {

	cin.tie(0);

	ios::sync_with_stdio(false);





	int N, M;

	cin >> N >> M;

	int to[100001], ne[100001], he[100001] = {};

	rep1(i, M) {

		int u, v;

		cin >> u >> v;

		to[i] = v;

		ne[i] = he[u];

		he[u] = i;

	}

	int S, T;

	cin >> S >> T;



	int D[300004];

	rep(i, 300004) D[i] = 1e9;

	D[3 * S] = 0;



	queue<PT> que;

	que.push(mp(0, 3 * S));

	while (que.size()) {

		PT p = que.front();

		que.pop();

		int i = p.second;

		if (D[i] < p.first) continue;

		int i2 = i / 3;

		for (int j = he[i2]; j; j = ne[j]) {

			int d = D[i] + 1;

			int j2 = to[j] * 3 + (i + 1) % 3;

			if (D[j2] > d) {

				D[j2] = d;

				que.push(mp(d, j2));

			}

		}

	}



	if (D[3 * T] == 1e9) co(-1);

	else co(D[3 * T] / 3);



	Would you please return 0;

}

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

#include<cstdio>

using namespace std;

typedef long long ll;

#define rep(i, n) for(int i = 0; i < (n); i++)

#define rep1(i, n) for(int i = 1; i <= (n); i++)

#define co(x) cout << (x) << "\n"

#define cosp(x) cout << (x) << " "

#define ce(x) cerr << (x) << "\n"

#define cesp(x) cerr << (x) << " "

#define pb push_back

#define mp make_pair

#define Would

#define you

#define please



const int cm = 1 << 17;

char cn[cm], * ci = cn + cm;

inline char getcha() {

	if (ci - cn == cm) { fread(cn, 1, cm, stdin); ci = cn; }

	return *ci++;

}

inline int getint() {

	char C = getcha();

	int A = C - '0';

	while ((C = getcha()) >= '0') A = A * 10 + C - '0';

	return A;

}



int main() {

	//cin.tie(0);

	//ios::sync_with_stdio(false);





	int N = getint(), M = getint();

	int to[100001], ne[100001], he[100001] = {};

	rep1(i, M) {

		int u = getint();

		to[i] = getint();

		ne[i] = he[u];

		he[u] = i;

	}

	int S = getint(), T = getint();



	int D[300004];

	rep(i, 300004) D[i] = 1e9;

	D[3 * S] = 0;



	int q[300000];

	int k1 = 0;

	int k2 = 1;

	q[0] = 3 * S;

	for (int k1 = 0; k1 < k2; k1++) {

		int i = q[k1];

		int i2 = i / 3;

		int d = D[i] + 1;

		for (int j = he[i2]; j; j = ne[j]) {

			int j2 = to[j] * 3 + (i + 1) % 3;

			if (D[j2] > d) {

				D[j2] = d;

				q[k2++] = j2;

			}

		}

	}



	if (D[3 * T] == 1e9) printf("-1");

	else printf("%d", D[3 * T] / 3);



	Would you please return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

#define rep(i, n) for(int i = 0; i < (n); i++)

#define rep1(i, n) for(int i = 1; i <= (n); i++)

#define co(x) cout << (x) << "\n"

#define cosp(x) cout << (x) << " "

#define ce(x) cerr << (x) << "\n"

#define cesp(x) cerr << (x) << " "

#define pb push_back

#define mp make_pair

#define Would

#define you

#define please



int main() {

	cin.tie(0);

	ios::sync_with_stdio(false);





	int N, M;

	cin >> N >> M;

	int to[100001], ne[100001], he[100001] = {};

	rep1(i, M) {

		int u, v;

		cin >> u >> v;

		to[i] = v;

		ne[i] = he[u];

		he[u] = i;

	}

	int S, T;

	cin >> S >> T;



	int D[300004];

	rep(i, 300004) D[i] = 1e9;

	D[3 * S] = 0;



	queue<ll> que;

	que.push(3 * S);

	while (que.size()) {

		ll p = que.front();

		que.pop();

		int i = p & ((1 << 20) - 1);

		int d = p >> 20;

		if (D[i] < d) continue;

		int i2 = i / 3;

		d++;

		for (int j = he[i2]; j; j = ne[j]) {

			int j2 = to[j] * 3 + (i + 1) % 3;

			if (D[j2] > d) {

				D[j2] = d;

				que.push(((ll)d << 20) + j2);

			}

		}

	}



	if (D[3 * T] == 1e9) co(-1);

	else co(D[3 * T] / 3);



	Would you please return 0;

}

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

#include<cstdio>

using namespace std;

typedef long long ll;

#define rep(i, n) for(int i = 0; i < (n); i++)

#define rep1(i, n) for(int i = 1; i <= (n); i++)

#define co(x) cout << (x) << "\n"

#define cosp(x) cout << (x) << " "

#define ce(x) cerr << (x) << "\n"

#define cesp(x) cerr << (x) << " "

#define pb push_back

#define mp make_pair

#define Would

#define you

#define please



const int cm = 1 << 17;

char cn[cm], * ci = cn + cm;

inline char getcha() {

	if (ci - cn == cm) { fread(cn, 1, cm, stdin); ci = cn; }

	return *ci++;

}

inline int getint() {

	char C = getcha();

	int A = C - '0';

	while ((C = getcha()) >= '0') A = A * 10 + C - '0';

	return A;

}



int main() {

	//cin.tie(0);

	//ios::sync_with_stdio(false);





	int N = getint(), M = getint();

	int to[100001], ne[100001], he[100001] = {};

	rep1(i, M) {

		int u = getint();

		to[i] = getint();

		ne[i] = he[u];

		he[u] = i;

	}

	int S = getint(), T = getint();



	int D[300004];

	rep(i, 300004) D[i] = 1e9;

	D[3 * S] = 0;



	int q[300000];

	int k1 = 0;

	int k2 = 1;

	q[0] = 3 * S;

	for (int k1 = 0; k1 < k2; k1++) {

		int i = q[k1];

		int i2 = i / 3;

		int d = D[i] + 1;

		for (int j = he[i2]; j; j = ne[j]) {

			int j2 = to[j] * 3 + (i + 1) % 3;

			if (D[j2] > d) {

				D[j2] = d;

				q[k2++] = j2;

			}

		}

	}



	if (D[3 * T] == 1e9) printf("-1");

	else printf("%d", D[3 * T] / 3);



	Would you please return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

#define rep(i, n) for(int i = 0; i < (n); i++)

#define rep1(i, n) for(int i = 1; i <= (n); i++)

#define co(x) cout << (x) << "\n"

#define cosp(x) cout << (x) << " "

#define ce(x) cerr << (x) << "\n"

#define cesp(x) cerr << (x) << " "

#define pb push_back

#define mp make_pair

#define Would

#define you

#define please



int main() {

	cin.tie(0);

	ios::sync_with_stdio(false);





	int N, M;

	cin >> N >> M;

	int to[100001], ne[100001], he[100001] = {};

	rep1(i, M) {

		int u, v;

		cin >> u >> v;

		to[i] = v;

		ne[i] = he[u];

		he[u] = i;

	}

	int S, T;

	cin >> S >> T;



	int D[300004];

	rep(i, 300004) D[i] = 1e9;

	D[3 * S] = 0;



	queue<int> que;

	que.push(3 * S);

	while (que.size()) {

		int i = que.front();

		que.pop();

		int i2 = i / 3;

		int d = D[i] + 1;

		for (int j = he[i2]; j; j = ne[j]) {

			int j2 = to[j] * 3 + (i + 1) % 3;

			if (D[j2] > d) {

				D[j2] = d;

				que.push(j2);

			}

		}

	}



	if (D[3 * T] == 1e9) co(-1);

	else co(D[3 * T] / 3);



	Would you please return 0;

}

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

#include<cstdio>

using namespace std;

typedef long long ll;

#define rep(i, n) for(int i = 0; i < (n); i++)

#define rep1(i, n) for(int i = 1; i <= (n); i++)

#define co(x) cout << (x) << "\n"

#define cosp(x) cout << (x) << " "

#define ce(x) cerr << (x) << "\n"

#define cesp(x) cerr << (x) << " "

#define pb push_back

#define mp make_pair

#define Would

#define you

#define please



const int cm = 1 << 17;

char cn[cm], * ci = cn + cm;

inline char getcha() {

	if (ci - cn == cm) { fread(cn, 1, cm, stdin); ci = cn; }

	return *ci++;

}

inline int getint() {

	char C = getcha();

	int A = C - '0';

	while ((C = getcha()) >= '0') A = A * 10 + C - '0';

	return A;

}



int main() {

	//cin.tie(0);

	//ios::sync_with_stdio(false);





	int N = getint(), M = getint();

	int to[100001], ne[100001], he[100001] = {};

	rep1(i, M) {

		int u = getint();

		to[i] = getint();

		ne[i] = he[u];

		he[u] = i;

	}

	int S = getint(), T = getint();



	int D[300004];

	rep(i, 300004) D[i] = 1e9;

	D[3 * S] = 0;



	int q[300000];

	int k1 = 0;

	int k2 = 1;

	q[0] = 3 * S;

	for (int k1 = 0; k1 < k2; k1++) {

		int i = q[k1];

		int i2 = i / 3;

		int d = D[i] + 1;

		for (int j = he[i2]; j; j = ne[j]) {

			int j2 = to[j] * 3 + (i + 1) % 3;

			if (D[j2] > d) {

				D[j2] = d;

				q[k2++] = j2;

			}

		}

	}



	if (D[3 * T] == 1e9) printf("-1");

	else printf("%d", D[3 * T] / 3);



	Would you please return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
//#include<bits/stdc++.h>

#include<cstdio>

#include<queue>

using namespace std;

typedef long long ll;

#define rep(i, n) for(int i = 0; i < (n); i++)

#define rep1(i, n) for(int i = 1; i <= (n); i++)

#define co(x) cout << (x) << "\n"

#define cosp(x) cout << (x) << " "

#define ce(x) cerr << (x) << "\n"

#define cesp(x) cerr << (x) << " "

#define pb push_back

#define mp make_pair

#define Would

#define you

#define please



const int cm = 1 << 17;

char cn[cm], * ci = cn + cm;

inline char getcha() {

	if (ci - cn == cm) { fread(cn, 1, cm, stdin); ci = cn; }

	return *ci++;

}

inline int getint() {

	char C = getcha();

	int A = C - '0';

	while ((C = getcha()) >= '0') A = A * 10 + C - '0';

	return A;

}



int main() {

	//cin.tie(0);

	//ios::sync_with_stdio(false);





	int N = getint(), M = getint();

	int to[100001], ne[100001], he[100001] = {};

	rep1(i, M) {

		int u = getint();

		to[i] = getint();

		ne[i] = he[u];

		he[u] = i;

	}

	int S = getint(), T = getint();



	int D[300004];

	rep(i, 300004) D[i] = 1e9;

	D[3 * S] = 0;



	queue<int> que;

	que.push(3 * S);

	while (que.size()) {

		int i = que.front();

		que.pop();

		int i2 = i / 3;

		int d = D[i] + 1;

		for (int j = he[i2]; j; j = ne[j]) {

			int j2 = to[j] * 3 + (i + 1) % 3;

			if (D[j2] > d) {

				D[j2] = d;

				que.push(j2);

			}

		}

	}



	if (D[3 * T] == 1e9) printf("-1");

	else printf("%d", D[3 * T] / 3);



	Would you please return 0;

}

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

#include<cstdio>

using namespace std;

typedef long long ll;

#define rep(i, n) for(int i = 0; i < (n); i++)

#define rep1(i, n) for(int i = 1; i <= (n); i++)

#define co(x) cout << (x) << "\n"

#define cosp(x) cout << (x) << " "

#define ce(x) cerr << (x) << "\n"

#define cesp(x) cerr << (x) << " "

#define pb push_back

#define mp make_pair

#define Would

#define you

#define please



const int cm = 1 << 17;

char cn[cm], * ci = cn + cm;

inline char getcha() {

	if (ci - cn == cm) { fread(cn, 1, cm, stdin); ci = cn; }

	return *ci++;

}

inline int getint() {

	char C = getcha();

	int A = C - '0';

	while ((C = getcha()) >= '0') A = A * 10 + C - '0';

	return A;

}



int main() {

	//cin.tie(0);

	//ios::sync_with_stdio(false);





	int N = getint(), M = getint();

	int to[100001], ne[100001], he[100001] = {};

	rep1(i, M) {

		int u = getint();

		to[i] = getint();

		ne[i] = he[u];

		he[u] = i;

	}

	int S = getint(), T = getint();



	int D[300004];

	rep(i, 300004) D[i] = 1e9;

	D[3 * S] = 0;



	int q[300000];

	int k1 = 0;

	int k2 = 1;

	q[0] = 3 * S;

	for (int k1 = 0; k1 < k2; k1++) {

		int i = q[k1];

		int i2 = i / 3;

		int d = D[i] + 1;

		for (int j = he[i2]; j; j = ne[j]) {

			int j2 = to[j] * 3 + (i + 1) % 3;

			if (D[j2] > d) {

				D[j2] = d;

				q[k2++] = j2;

			}

		}

	}



	if (D[3 * T] == 1e9) printf("-1");

	else printf("%d", D[3 * T] / 3);



	Would you please return 0;

}

// Fastest known solution for this problem: