unittest
{
//	assert( [ "4 5", "1 2", "2 3", "2 4", "4 1", "4 3" ].parse.expand.solve == "3\n1\n2\n4" );
	assert( [ "4 5", "1 2", "2 3", "2 4", "4 1", "4 3" ].parse.expand.solve == "3\n2\n4\n1" );
	assert( [ "4 5", "1 2", "2 3", "2 4", "1 4", "4 3" ].parse.expand.solve == "-1" );
//	assert( [ "6 9", "1 2", "2 3", "3 4", "4 5", "5 6", "5 1", "5 2", "6 1", "6 2" ].parse.expand.solve == "4\n2\n3\n4\n5" );
	assert( [ "6 9", "1 2", "2 3", "3 4", "4 5", "5 6", "5 1", "5 2", "6 1", "6 2" ].parse.expand.solve == "4\n3\n4\n5\n2" );
}



import std.conv;
import std.format;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto nm = input.front.split.to!( long[] );
	auto abs = new long[ 2 ][ nm[ 1 ] ];
	foreach( ref ab; abs )
	{
		input.popFront;
		ab = input.front.split.to!( long[] );
	}
	return tuple( nm[ 0 ], abs );
}

auto solve( long n, long[ 2 ][] abs )
{
	// 辺を頂点基準に変換
	auto nss = new long[][ 1 + n ];
	auto rss = new long[][ 1 + n ];
	foreach( ab; abs )
	{
		nss[ ab[ 0 ] ] ~= ab[ 1 ];
		rss[ ab[ 1 ] ] ~= ab[ 0 ];
	}
	
	// 最短のサイクルを判定
	auto ms = [ long.max ];
	auto mi = 0L;
	foreach( ab; abs )
	{
		auto ds = bfs( nss, ab[ 1 ], ab[ 0 ] );
		if( ms[ mi ] <= ds[ ab[ 0 ] ] ) continue;
		ms = ds;
		mi = ab[ 0 ];
	}
	if( ms[ mi ] == long.max ) return "-1";		// サイクルなし
	
	// 経路を復元
	auto anss = new long[ ms[ mi ] + 1 ];
	anss[ $ - 1 ] = mi;
	auto t = mi;
	for( auto i = anss.length.signed - 1; 0 < i; i-- )
	{
		foreach( f; rss[ t ] )
		{
			if( ms[ f ] == ms[ t ] - 1 )
			{
				t = f;
				break;
			}
		}
		anss[ i - 1 ] = t;
	}
	return format( "%s\n%s", anss.length, anss.to!( string[] ).join( "\n" ) );
}

// グラフの始点終点指定最短経路探索（幅優先探索）
auto bfs( long[][] nss, long s, long g )
{
	import std.container.dlist;
	
	auto ds = new long[ nss.length ];
	ds[] = long.max;
	ds[ s ] = 0;
	auto queue = make!DList( s );
	while( !queue.empty )
	{
		auto f = queue.front;
		queue.removeFront();
		
		foreach( t; nss[ f ] )
		{
			if( ds[ t ] < long.max ) continue;
			ds[ t ] = ds[ f ] + 1;
			if( t == g ) break;
			queue.insertBack( t );
		}
	}
	return ds;
}
