N,M = map(int, input().split())
Num = ["0","0","0"]
for _ in range(M):
  num = input().split()
  if int(num[0]) <= 3:
    Num[int(num[0])-1] = num[1]
number = int(''.join(Num))
result = -1
for i in range(1, 999):
  if i == number:
    result = number
    break
print(result)