SC=[]
N,M = map(int,input().split())

for _ in range(M):
    SC.append(list(map(int,input().split())))

ans=[[0] for i in range(N)]
for value in SC:
    ans[value[0]-1].append(value[1])

keta=100
answ=0
for a in ans:
    tmp=0
    for i in a:
        if(i!=0):
            if(tmp==0):
                tmp=i
            elif(tmp > i):
                tmp=i
        
    answ+=tmp*keta
    keta=keta//10

print(answ) if(len(str(answ))==N) else print(-1)

