n,m = map(int,input().split())
sc = [list(map(int,input().split())) for _ in range(m)]
if (m == 0) and (n != 1):
  print(10**(n-1))
  exit()
elif (m == 0) and (n == 1):
  print(0)
  exit()
for i in range(1,1000):
  i = str(i)
  for j in range(m):
    try:
      if i[sc[j][0] - 1] ==  str(sc[j][1]):
        pass
      else:
        break
    except:
      break
    if j == m-1:
      print(i)
      exit()
print(-1)