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
  else:
    rep[s] = str(c)

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

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