N, M = map(int, input().split())
num = [-1]*N
err = False
for _ in range(M):
  s, c = map(int, input().split())
  if num[s-1] == -1:
    num[s-1] = c
  else:
    if num[s-1] != c:
      err = True
if err or (N > 1 and num[0] == 0):
  print(-1)
else:
  ans = 0
  i = 0
  n = 0
  while i < N:
    if num[i] < 0:
      n = 1 if i == 0 else 0
    else:
      n = num[i]
    ans = ans * 10 + n
    i += 1
  print(ans)