#pragma
#pragma
#pragma
#pragma
#pragma
#pragma
#include <bits/stdc++.h>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define
typedef long long ll;
#define
#define
template<class T> inline T min(T &x,const T &y){return x>y?y:x;}
template<class T> inline T max(T &x,const T &y){return x<y?y:x;}
//#define getchar()(p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2) ? EOF : *p1++)
//char buf[(1 << 21) + 1], *p1 = buf, *p2 = buf;
ll read(){ll c = getchar(),Nig = 1,x = 0;while(!isdigit(c) && c!='-')c = getchar();
if(c == '-')Nig = -1,c = getchar();
while(isdigit(c))x = ((x<<1) + (x<<3)) + (c^'0'),c = getchar();
return Nig*x;}
#define
const ll inf = 1e15;
const int maxn = 2e3 + 7;
const int mod = 1e9 + 7;
#define
#define
ll n,ans,k,f,t,number[maxn][maxn];
struct node{
int sum;
int num;
}a[maxn];
bool cmp(node a,node b)
{
if(a.sum!=b.sum) return a.sum>b.sum;
else return a.num<b.num;
}
void dfs(int sum, unsigned char ss){
if(sum>n)
return;
if(ss==07)
ans++;
if(sum<99999999){
dfs(sum*10+3,ss|1);
dfs(sum*10+5,ss|2);
dfs(sum*10+7,ss|4);
}
}
ll superpow(ll a,ll b,ll c){
ll ans=1;
ll temp=a;
while(b){
if(b&1) ans=(ans*temp)%c;
temp=(temp*temp)%c;
b>>=1;
}
return ans;
}
start{
/**
ll x=read;
if(x==7||x==5||x==3)
printf("YES\n");
else
printf("NO\n");
string s;
cin>>s;
int len=s.size();
int ans=999;
for(int i=0;i<=len-3;++i)
{
int num=(s[i]-'0')*100+(s[i+1]-'0')*10+(s[i+2]-'0');
ans=min(abs(num-753),ans);
}
cout<<ans;
n=read;
dfs(0,0);
cout<<ans;
n=read,k=read;
for(int i=1;i<=10;i++) e[i]=read;
for(int i=1;i<=n;i++) {
a[i].sum=read;
a[i].num=i;
}
sort(a+1,a+1+n,cmp);
for(int i=1;i<=n;i++)
a[i].sum+=e[(i-1)%10+1];
sort(a+1,a+1+n,cmp);
for(int i=1;i<=k;i++)
{
if(i==1)
printf("%d",a[i].num);
else
printf(" %d",a[i].num);
}
printf("\n");
n=read,k=read;
printf("%lld\n",(superpow(3,n-1,k<<1)+1)>>1);**/
n=read;
f=read;
t=read;
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
{
number[i][j]=mod;
number[i][i]=0;
}
for(int i=1;i<=n;i++)
{
k=read;
for(int j=1;j<=k;j++){
int a=read;
if(j==1) number[i][a]=0;
else number[i][a]=1;
}
}
for(int k=1;k<=n;k++)
{
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
number[i][j]=min(number[i][j],number[i][k]+number[k][j]);
}
}
}
if(number[f][t]==mod) printf("-1\n");
else
printf("%d\n",number[f][t]);
end;
}