# include # include # define DIM 5005 # include # include using namespace std; vector< vector< int > > mat( DIM ); vector< int > grad_zero( DIM ), X( DIM ), viz( DIM ), fii( DIM ); int n, k, cont, maxim, nod; inline void afisare() { //ofstream fout( "influence.out" ); for( int i = 1; i <= n; ++i ) if( fii[ i ] > maxim && X[ i ] == 1 ) { maxim = fii[ i ]; nod = i; } cout << nod; } inline void df( int x ) { for( int i = 0; i < mat[ x ].size(); ++i ) if( ! viz[ mat[ x ][ i ] ]) { viz[ mat[ x ][ i ] ] = 1; cont ++; df( mat[ x ][ i ] ); } } inline void citire() { //ifstream fin("influence.in"); cin >> n >> k; for( int i = 0; i < k; ++i ) { int x; cin >> x; X[ x ] = 1; } for ( int i = 1; i <= n; ++i ) { int tata; cin >> tata; while( cin.peek () != '\n' ) { int x; cin >> x; mat[ tata ].push_back( x ); grad_zero[ x ] = 1; } } for( int i = 1; i <= n; ++i ) if( grad_zero[ i ] == 0 ) mat[ 0 ].push_back( i ); } int main() { citire(); for( int i = 0; i < mat[ 0 ].size(); ++i ) { cont = 0; for( int j = 0; j <= n; ++j ) viz[ j ] = 0; df( mat[ 0 ][ i ] ); fii[ mat[ 0 ][ i ] ] = cont; } afisare(); }