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

ok = False
n = [-1] * M
for s, c in sc:
  if n[s-1] != -1:
    if n[s-1] == c: continue
    ans = -1
    ok = True
    break
  n[s-1] = c

if n[0] == 0:
  ans = -1
  ok = True
if not ok:
  ans = ""
  for i in range(M):
    if i == 0 and n[i] == -1:
      ans += "1"
    elif n[i] == -1:
      ans += "0"
    else:
      ans += str(n[i])
print(ans)