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

ans = [None for _ in range(N)]

flag = True
for p in P:
  keta = int(p[0])-1
  val = int(p[1])
  if keta == 0 and val == 0:
    flag = False
  if not ans[keta]:
    ans[keta] = val
  else:
    if ans[keta] != val:
      flag = False
fin = ""
if flag:
  for i, a in enumerate(ans):
    if a:
      fin += str(a)
    else:
      if i == 0:
        fin += "1"
      else:
        fin += "0"
  print(int(fin))
else:
  print(-1)