#include < iostream >
using   namespace  std;
int  map[ 101 ][ 101 ];
int  dir[ 101 ];
bool  visit[ 101 ];
int  s,e;
int  n,m,t;
int  best = INT_MAX;
bool  flag;
void  solve( int  t, int  tol)
{   
int  i;
    visit[t]
= 1 ;
    
if (tol > best)
    {   visit[t]
= 0 ;
        
return  ;
    }
    
if (t == e)
    {   visit[t]
= 0 ;
        
if (tol < best)
            best
= tol;
        
return  ;
    }
    
for (i = 1 ;i <= n;i ++ )
    {   
        
if ( ! visit[i] && map[t][i])
        {  
             
if (dir[t] == i)
             {   
                 solve(i,tol);
             }
             
else
             {   
                 solve(i,tol
+ 1 );
                 
             }
    
        }
    }
    visit[t]
= 0 ;
}
int  main()
{   
int  i,j;
    scanf(
" %d%d%d " , & n, & s, & e);
    
for (i = 1 ;i <= n;i ++ )
    {   
        scanf(
" %d " , & m);
        
bool index = 0 ;
        
while (m -- )
        {    scanf(
" %d " , & t);
             
if (index == 0 )
             {   dir[i]
= t;
                 index
= 1 ;
             }
             map[i][t]
= 1 ;
        } 
    }
    solve(s,
0 );
    
if (best < INT_MAX)
        printf(
" %d\n " ,best);
    
else
    {   
        printf(
" -1\n " );
    }
    system(
" pause " );
    
return   0 ;
}