n, m  = map( int, input().split() )
ans_flag = True
ans = [0] * n
for _ in range( m ):
  s, c = map(int, input().split())
  if not( ans[ s - 1 ] in [ 0, c ] ):
    ans_flag = False
    break
  ans[ s - 1 ] = c

a = ""
for i in range( len( ans )):
  a += str( ans[ i ])
a = str( int(a) )
if ans_flag and ( len(a) == n ):
  print( a )
else:
  print( -1 )
