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



import std.algorithm;
import std.container;
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[] );
		ab[] -= 1;
	}
	return tuple( nm[ 0 ], abs );
}

auto solve( long n, long[ 2 ][] abs )
{
	auto anss = new long[ n - 1 ];
	
	auto nss = toAdjacencyList!true( n,abs );
	auto ds = new long[ nss.length ];
	ds[] = long.max;
	ds[ 0 ] = 0;
	
	auto queue = make!DList( 0L );
	while( !queue.empty )
	{
		auto f = queue.front;
		queue.removeFront();
		
		foreach( t; nss[ f ] )
		{
			if( ds[ t ] < long.max ) continue;
			
			ds[ t ] = ds[ f ] + 1;
			anss[ t - 1 ] = f + 1;
			queue.insertBack( t );
		}
	}
	if( ds.find( 0 ).empty ) return "No";
	else                     return format( "Yes\n%s", anss.to!( string[] ).join( "\n" ) );
}

// 辺配列から隣接リストを作成
auto toAdjacencyList( bool undirected = false )( long n, long[ 2 ][] es )
{
	auto nss = new long[][ n ];
	foreach( e; es )
	{
		nss[ e[ 0 ] ] ~= e[ 1 ];
		static if( undirected ) nss[ e[ 1 ] ] ~= e[ 0 ];
	}
	return nss;
}
