n,m=map(int,input().split())
s=[0]*m
c=[0]*m
if m == 0 and n != 1:  
    print(10 ** (n - 1))
    exit()
elif m == 0 and n == 1: 
    print(0)
    exit()
for i in range(m):
    s[i],c[i]=map(int,input().split())
ans_100=0
ans_10=0
ans_1=0
for i in range(m):
    if n-s[i]==2:
        if ans_100>c[i]*(10**2):
            ans_100=c[i]*(10**2)
    elif n-s[i]==1:
        if ans_10>c[i]*10:
            ans_10=c[i]*10
    elif n-s[i]==0:
        if ans_1>c[i]:
            ans_1=c[i]
if n==1:
    print(ans_1)
elif ans_100+ans_10+ans_1>=10**(n-1) and ans_100+ans_10+ans_1<=1000:
    print(ans_100+ans_10+ans_1)
else :
    print(-1)