line = ["0", "0", "0"]
number = ''
cnt1=cnt2=cnt3=0
d1=d2=d3=0

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

for y in range(M):
    s,c=input().split()
    ss = int(s)
    S = int(s)-1
    line[S] = c
    
    if ss == 1:
        cnt1 += 1
        if cnt1==1:
            d1=int(c)
    elif ss == 2:
        cnt2 += 1
        if cnt2==1:
            d2=int(c)
    elif ss == 3:
        cnt3 += 1
        if cnt3==1:
            d3=int(c)
    
    if cnt1 > 1 and not int(c)==d1:
        line[S] = '0'
    elif cnt2 > 1 and not int(c)==d2:
        line[S] = '0'
    elif cnt3 > 1 and not int(c)==d3:
        line[S] = '0'
#print(line)

if N==1:
    line.reverse()

if N==2:
    line[2] = line[1]
    line[1] = line[0]
    line[0] = '0'

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

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