
N, M=(int(i) for i in input().split())
P=[[int(i) for i in input().split()] for  _ in range(M)]
P=[[P[i][0]-1,P[i][1]] for i in range(M)]
f=True

ans=["*"]*N
for i in range(M):
    if ans[P[i][0]]!="*" and ans[P[i][0]]!=str(P[i][1]):
        print(-1)
        f=False
    else:
        ans[P[i][0]]=str(P[i][1])
if N==1 and P[0][1]==0 and f:
    print(0)
else:
    if f:
        if ans[0]=="*":
            ans[0]=1
        for i in range(1,N):
            if ans[i]=="*":
                ans[i]="0"
        if len(str(int("".join(ans))))==N:
            print(int("".join(ans)))
        else:
            print(-1)
