#include<bits/stdc++.h>
using namespace std;
const int maxn=10010,maxm=200010;
int n,m,head[maxn],tail[maxn],s,t,e=0,r1,r2,r3,d[maxn];
bool vis[maxn],bbb[maxn]={};
struct edge
{
int from,to,next1,next2,val;
bool bb;
}ed[maxm];
inline void addedge(int x,int y)
{
ed[++e].to=y;
ed[e].from=x;
ed[e].next1=head[x];
head[x]=e;
ed[e].next2=tail[y];
tail[y]=e;
ed[e].val=1;
}
void dfs1(int x)
{
vis[x]=1;
for(int i=tail[x];i;i=ed[i].next2)
{
int y=ed[i].from;
ed[i].bb=1;
if(vis[y])continue;
dfs1(y);
}
}
inline void spfa()
{
memset(vis,false,sizeof(vis));
memset(d,0x3f3f3f3f,sizeof(d));
if(bbb[s])return;
queue<int> q;
q.push(s);
vis[s]=1;
d[s]=0;
while(!q.empty())
{
int x=q.front();
q.pop();
vis[x]=0;
for(int i=head[x];i;i=ed[i].next1)
{
int y=ed[i].to;
if(bbb[y])continue;
if(d[y]>d[x]+ed[i].val)
{
d[y]=d[x]+ed[i].val;
if(!vis[y])
{
q.push(y);
vis[y]=1;
}
}
}
}
}
int main()
{
scanf("%d%d",&n,&m);
for(int i=1;i<=m;i++)
{
scanf("%d%d",&r1,&r2);
if(r1==r2)continue;
addedge(r1,r2);
}
scanf("%d%d",&s,&t);
memset(vis,false,sizeof(vis));
dfs1(t);
for(int i=1;i<=n;i++)
{
for(int j=head[i];j;j=ed[j].next1)
if(!ed[j].bb)bbb[i]=1;
}
spfa();
if(d[t]>=0x3f3f3f3f)printf("-1");
else printf("%d",d[t]);
return 0;
}