import itertools

N, M = map(int, input().split())
a = [[0] * 10] * 3

for i in range(N):
  if i == 0:
    a[i] = [1, 2, 3, 4, 5, 6, 7, 8, 9]
  else:
    a[i] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

flag = 1

for i in range(M):
  s, c = map(int, input().split())
  if s == 1 and c == 0 or len(a[s-1]) == 1 and a[s-1] != [c]:
    flag = 0
  a[s-1] = [c]

if flag == 0:
  print(-1)
else:
  list_a = list(itertools.product(*a))
  ans = ""
  for i in range(N):
    ans += str(list_a[0][i])
  print(ans)