n, m = map(int, input().split())

scs = []
for i in range(m):
    scs.append(list(map(int, input().split())))
    
number = [-1] * n
for sc in scs:
    if number[sc[0] - 1] == -1:
        number[sc[0] - 1] = sc[1]
    elif number[sc[0] - 1] != sc[1]:
        number = []
        break
        
if len(number) > 1 and number[0] != 0:
    guess = 0
    for i in range(n):
        if number[i] != -1: 
            guess += number[i] * (10 ** (n - i - 1))
        elif i == 0 :
            guess += (10 ** (n - i - 1))

else:
    guess = -1
    
print(guess)