N , M = map ( int , input().strip().split(" ") ) ;

dic = {} ;
b1 = True ;
for x in range ( M ) :
	s , c = map ( int , input().strip().split(" ") ) ;
	if s in dic and dic[s] != c :
		b1 = False ;
		break ;
	else :
		dic[s] = c ;

if b1 :
	s = "" ; 
	for k in range ( 1 , N+1 ) :
		if not k in dic :
			if k == 1 :
				s += "1" ;
			else :
				s += "0" ;
		else :
			s += str(dic[k]) ;
	if s.startswith( "0" ) and N >= 2 :
		print ( -1 ) ; 
	else :
		print ( s ) ;
else :
	print ( -1 ) ;
