N, M = map(int, input().split())
sc = [list(map(int, input().split())) for _ in range(M)]

ans = ["0"] * N
if N > 1: ans[0] = "1"
rep = {}
ok = True

for s,c in sc:
  ans[s-1] = str(c)
  if s in rep and rep[s] != str(c):
    ok = False
    break
  else:
    rep[s] = c

if ok and ans[0] == "0" and N > 1:
  ok = False

print("".join(ans) if ok else -1)