n,m = map(int, input().split())
sc=[list(map(int,input().split())) for i in range(m)]
s=[]
c=[]
f=0
ans=[str(0) for i in range(n)]
for i in range(m):
    if sc[i][0]==1 and sc[i][1]==0 and n!=1:
        f=-1
        break
    else:
        if sc[i][0] in s:
            if sc[i][1]!=c[s.index(sc[i][0])]:
                f=-1
                break
        else:
            ans[sc[i][0]-1]=str(sc[i][1])
            s.append(sc[i][0])
            c.append(sc[i][1])
if f==-1:
    print(-1)
else:
    if n==1:
        print(''.join(ans))
    else:
        if ans[0]==str(0):
            ans[0]==str(1)
        print(''.join(ans))
