n,m=map(int,input().split())
ky=[b+1 for b in range(n)]
vl=[-1 for a in range(n)]
ans=dict(zip(ky,vl))
rs=str()
bl=True
for i in range(m):
    date=list(map(int,input().split()))
    if date[0]==1:
        if date[1]==0:
            print("-1")
            bl=False
            break
        elif ans[1]==-1:
            ans[1]=date[1]
        elif ans[1]==date[1]:
            pass
        else:
            print("-1")
            bl=False
            break
    elif date[0]==2:
        if ans[2]==-1:
            ans[2]=date[1]
        elif ans[2]==date[1]:
            pass
        else:
            print("-1")
            bl=False
            break
    elif date[0]==3:
        if ans[3]==-1:
            ans[3]=date[1]
        elif ans[3]==date[1]:
            pass
        else:
            print(-1)
            bl=False
            break
for b in range(n):
    if n==1 and ans[1]==-1:
        ans[1]=0
    elif ans[b+1]==-1:
        if b+1==1:
            ans[1]=1
        else:
            ans[b+1]=0
for s in range(n):
    rs+=str(ans[s+1])
if bl:
    print(rs)