N,M=map(int,input().split())
S=[list(map(int,input().split())) for _ in range(M)]

D=[-1]*3
ans=True

for s,c in S:
    if D[s-1] == -1:
        D[s-1]=c
    else:
        if D[s-1] != c:
            ans=False
if D[3-N]==0: ans=False

if D[3-N]==-1: D[3-N]=1
for i in range(3):
    if D[i]==-1: D[i]=0 
     
print(''.join(map(str,D)) if ans else -1)