unittest
{
	assert( [ "3 3", "1 7", "3 2", "1 7" ].parse.expand.solve == 702 );
	assert( [ "3 2", "2 1", "2 3" ].parse.expand.solve == -1 );
	assert( [ "3 1", "1 0" ].parse.expand.solve == -1 );
	
	assert( [ "1 1", "1 0" ].parse.expand.solve == 0 );		// 追加ケース
	assert( [ "2 1", "1 0" ].parse.expand.solve == -1 );		// 追加ケース
	assert( [ "2 1", "2 1" ].parse.expand.solve == 11 );		// 追加ケース
	assert( [ "3 1", "2 3" ].parse.expand.solve == 130 );		// 追加ケース
	assert( [ "2 0" ].parse.expand.solve == 10 );		// 追加ケース
	assert( [ "1 0" ].parse.expand.solve == 0 );		// 追加ケース
}



import std.algorithm;
import std.conv;
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 scs = new long[ 2 ][ nm[ 1 ] ];
	foreach( ref sc; scs )
	{
		input.popFront;
		sc = input.front.split.to!( long[] );
		sc[ 0 ]--;
	}
	return tuple( nm[ 0 ], scs );
}

auto solve( long n, long[ 2 ][] scs )
{
	auto anss = new long[ n ];
	anss[] = -1;
	foreach( sc; scs.sort().uniq )
	{
		if( anss[ sc[ 0 ] ] != -1 ) return -1;
		anss[ sc[ 0 ] ] = sc[ 1 ];
	}
	if( anss[ 0 ] == 0 )
	{
		if( anss.length == 1 ) return 0;
		else                   return -1;
	}
	if( anss[ 0 ] == -1 )
	{
		if( anss.length == 1 ) anss[ 0 ] = 0;
		else                   anss[ 0 ] = 1;
	}
	foreach( i, ref ans; anss )
	{
		if( ans == -1 ) ans = 0;
	}
	return reduce!( ( a, b ) => a * 10 + b )( 0L, anss );
}
