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

C=[-1]*N

for i in range(M):
    s,c=map(int,input().split())
    if C[s-1]==-1:
        C[s-1]=c
    elif C[s-1]!=-1:
        if C[s-1]!=c:
            print(-1)
            exit()

if N==1 and C[0]==0:
    print(0)
    exit()

ans=""
for i in range(N):
    if C[i]==-1:
        if i==0:
            ans+="1"
        else:
            ans+="0"
    elif i==0 and C[i]==0:
        print(-1)
        exit()
    else:
        ans+=str(C[i])
print(ans)


