import sys
N,M = map(int,input().split())
source = []
goal = ''
L = [0 for _ in range(N)]
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]
        L[keta-1] = number
while L!= [] and L[0] == 0:
    L.remove(0)
if L == []:
  if N == 1:
    print(0)
    sys.exit(0)
  else:
    print(-1)
    sys.exit(0)
for i in range(len(L)):
  goal += str(L[i])
print(goal)