import sys
N,M = map(int,input().split())
source = []
goal = ''
for i in range(M):
  keta,number = map(int,input().split())
  source.append((keta,number))
source.sort()
#論外の処理：
for i in range(M):
    keta1,number1 = source[i]
    for j in range(M):
     	keta2,number2 = source[j]
     	if i != j and (keta1 == keta2) and (number1 != number2):
        	print('-1')
        	sys.exit(0)
for i in range(N):
  if i < len(source):
    keta,number = source[i]
    if i == keta-1:
      goal += str(number)
    else:
      goal += '0'
  else:
    goal += '0'
k = int(goal)
if len(str(k)) == len(goal):
  print(goal)
else:
  print('-1')