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=[]
ans_10=[]
ans_1=[]
for i in range(m):
    if s[i]!=0:
        if n-s[i]==2:
            ans_100.append(c[i]*(10**2))
        elif n-s[i]==1:
            ans_10.append(c[i]*10)
        elif n-s[i]==0:
            ans_1.append(c[i])
if not ans_100:
    ans_100.append(0)
if not ans_10:
    ans_10.append(0)
if not ans_1:
    ans_1.append(0)
if n==1:
    print(ans_1)
elif min(ans_100)+min(ans_10)+min(ans_1)>=10**(n-1) and min(ans_100)+min(ans_10)+min(ans_1)<=1000:
    print(min(ans_100)+min(ans_10)+min(ans_1))
else :
    print(-1)