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

n = [0] * N
n[0] = 1
d = {}
ok = True
for s,c in sc:
  if s in d:
    if d[s] == c: continue
    ok = False
    ans = -1
    break
  else:
    d[s] = c
    n[s-1] = c

if ok and n[0] == 0:
  ok = False
  ans = -1

if not ok: print(ans)
else:
  print("".join(map(str, n)))