N,M = list(map(int,input().split()))
a3 = [0]*10
a2 = [0]*10
a1 = [0]*10
for i in range(M):
    s,c = list(map(int,input().split()))
    if s ==1:
        a3[c] =1
    elif s == 2:
        a2[c] = 1
    elif s == 3:
        a1[c] = 1
flag = 0
#桁間違いの排除
if N==3 and (sum(a3)==0 or a3[0]==1):
    flag = -1
elif N == 2 and (sum(a3) != 0 or sum(a2) == 0 or a2[1]==0):
    flag = -1
elif N ==1 and (sum(a3)!= 0 or sum(a2) !=0 ):
    flag = -1
#重複の排除
elif sum(a3) >1 or sum(a2)>1 or sum(a1)>1:
    flag = -1
else:
    if sum(a3) == 0:
        a3[0]=1
    elif sum(a2) ==0:
        a2[0] =1
    elif sum(a1)==0:
        a1[0] =1
    
    for i in range(10):
        if a3[i]==1:
            flag += 100*i
        elif a2[i] ==1:
            flag += 10*i
        elif a1[i] ==1:
            flag += i
print(flag)
