from sys import exit
N, M = map(int, input().split())
num = [-1 for i in range(3)]
for i in range(M):
  s, c = map(int, input().split())
  if num[s - 1] != c and num[s - 1] != -1:
    print(-1)
    exit()
  else:
    num[s - 1] = c
flag = 0
index = 2
ans = 0
for n in num:
  if flag == 0:
    if n != -1:
      ans += n * 10 ** index
      flag += 1
  elif n != -1:
    ans += n * 10 ** index
  index -= 1
print(ans if 10 ** N > ans >= 10 ** (N - 1) else -1)