N,M=map(int,input().split())
S_C=[list(int(x) for x in input().split()) for _ in range(M)]
ans='000'

flag=0

for s,c in S_C:
    if ans[s-1]!='0' and ans[s-1]!=str(c):
        flag=1
    else:
        if s==1:
            ans=str(c)+ans[1:]
        elif s==2:
            ans=ans[0]+str(c)+ans[2]
        else:
            ans=ans[:2]+str(c)

print(ans if (flag==0 and ans!='000') else -1)

