n, m = map(int, input().split())
sc = [list(map(int, input().split())) for _ in range(m)]
ans = -1
for i in range(1000):
  s = str(i)
  if len(s) == n:
    ok = True
    for j, k in sc:
      if int(s[j-1]) != k:
        ok = False
    if ok:
      ans=i
      break
print(ans)