N,M=map(int,input().split())

sc = [list(map(int,input().split())) for _ in range(M)]
flag = 0
for i in range(M):
    if sc[i][0] ==N:
        flag=1
    else:
        continue
Nlist= [0]*N
ans=0
if flag == 0:
    print(-1)
else:
    for i in range(M):
        if (Nlist[sc[i][0]-1] == 1):
            continue
        else:
            Nlist[sc[i][0]-1]=1
            ans += pow(10,N-sc[i][0])*sc[i][1]
    print(ans)