n,m=map(int,input().split())
SC=[list(map(int,input().split())) for _ in range(m)]
ans=[0 for _ in range(n)]
ansh=[0 for _ in range(n)]
for sc in SC:
    if ansh[sc[0]-1]==0:
        ans[sc[0]-1]=sc[1]
        ansh[sc[0]-1]=1
    else:
        if ans[sc[0]-1]!=sc[1]:
            print(-1)
            exit()
if ans[0]!=0:
    print(*ans,sep="")
else:
    print(-1)