info = [int(n) for n in input().split()]

number = []
answer = 0

for i in range(info[0]):
  number.append(0)

keta = len(number)

for i in range(info[1]):
  lst = [int(n) for n in input().split()]

  if lst[0] == 1 and lst[1] == 0:
    answer = -1
  else:
    if number[lst[0]-1] == 0:
      number[lst[0]-1] = lst[1]
    else:
      if number[lst[0]-1] != lst[1]:
        answer = -1

if answer != -1:
  if number[0] == 0:
    number[0] += 1
  
  for i in range(keta):
    b = keta - i - 1
    answer += number[i]*(10 ** b)
  
print(answer)
    