import numpy as np
N , M = map(int, input().split())
ans = np.zeros(N)
S_C = []
for _ in range(M):
  s, c = map(int, input().split())
  for i, j in S_C:
    if s == i and c != j:
      print(-1)
      quit()
  ans[s-1] = c
  S_C.append([s, c])

if ans[0] == 0 and len(ans) != 1:
  print(-1)
  quit()
else:
  print(int("".join([str(int(x)) for x in ans])))