line = ["0", "0", "0"]
number = ''

N,M=(int(x) for x in input().split())

for y in range(M):
    s,c=input().split()
    S =int(s)-1
    #if not line[S] == "0": #ミスあり
    line[S] = c
print('line'line)

for z in line:
    #if not line[z] == "0":
    number += z
print(number)

if N == 3 and number[0]=='0':
    print('-1')
elif N == 2 and number[1]=='0':
    print('-1')
elif N == 1 and not number[0]=='0':
    print('-1')
elif N == 1 and not number[1]=='0':
    print('-1')    
elif number[0]=='0' and N==3:
    print('-1')
elif number[1]=='0' and N==2:
    print('-1')
elif number[2]=='0' and N==1:
    print('-1')
else:
    number = int(number)
    print(number)
