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

number = []
answer = 0

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

keta = info[0]

if keta == 1:
  if info[1] > 1:
    answer = -1
  elif info[1] == 0:
    answer = 0
  else:
    answer = number[0]
else:
  for i in range(info[1]):
    lst = [int(n) for n in input().split()]

    if lst[0] == 1 and lst[0] == 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 and keta != 1:
      number[0] += 1
    
    for i in range(keta):
      b = keta - i - 1
      answer += number[i]*(10 ** b)
    
print(answer)