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:
  if s in rep:
    if rep[s] == c: continue
    ok = False
    break
  else:
    rep[s] = c
    ans[s-1] = c

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

else:
  print("".join(map(str, ans)) if ok else -1)