n,m=map(int,input().split())
s=[0]*m
c=[0]*m
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]+1==3:
        if ans_100<c[i]*(10**2):
            ans_100=c[i]*(10**2)
    elif n-s[i]+1==2:
        if ans_10<c[i]*10:
            ans_10=c[i]*10
    elif n-s[i]+1==1:
        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):
    print(-1)
else :
    print(ans_100+ans_10+ans_1)