n,m=map(int,input().split())

b=[list(map(int,input().split())) for i in range(m)]

if n==1:
  for i in range(10):
    
    flg=True
    for l in range(m):
      if b[l][1]  != 0:
        flg=False
    if flg==True:
      print(0)
      break
  else:
    print(-1)
  
else:  
  for i in range(10**(n-1),10**n):
    flg=True
    for j in range(m):
      if str(i)[b[j][0]-1] != str(b[j][1]):
        flg=False
    
    if flg==True:
      print(i)
      break
  if flg == False:
    print(-1)

