N,M = (int(i) for i in input().split())

SC = []
max_digits = 0
for i in range(M):
  S,C = (int(i) for i in input().split())
  SC.append([S,C])
  max_digits = max(max_digits,S)

ans = -1
for i in range(10**(max_digits-1),10**(max_digits)):
  check_flag = True
  for sc in SC:
    s = sc[0]
    c = sc[1]
    if str(i)[s-1] != str(c):
      check_flag = False
      break
  if check_flag is True:
    ans = i
    break

print(ans)
