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

sc = [list(map(int,input().split())) for _ in range(M)]
flag = 1
for i in range(M):
    if sc[i][0] ==1:
        if sc[i][1]==0:
            flag=0
    for j in range(M):
        if sc[i][0] == sc[j][0]:
            if sc[i][1] != sc[j][1]:
                flag =0
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)
