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