N, M = map(int,input().split())
L = [[int(x) for x in input().split()]for i in range(M)]

if M == 0:
  print(10**(N-1))
  exit()
  
number = [None]*N  
for i in range(M):
  if L[i][0] == 1 and L[i][1] == 0:
    print(-1)
    exit()
  elif number[L[i][0]-1]==None:
    number[L[i][0]-1]=L[i][1]
  elif number[L[i][0]-1]==L[i][1]:
    continue
  else:
    print(-1)
    exit()

Sum = 0    
    
if number[0]==None:
  Sum += 10**(N-1)
  for i in range(1,N):
    if number[i]!=None:
      Sum += number[i]*(10**(N-i-1))
    
else:
  for i in range(N):
    if number[i]!=None:
      Sum += number[i]*(10**(N-i-1))
    
print(Sum)

  