n,m=map(int,input().split())
ans=[0]*n
temp=[0]*n
for i in range(m):
    s,c=map(int,input().split())
    if temp[s-1]==0 or (temp[s-1]!=0 and ans[s-1]==c):
        if s-1==0 and c==0:
            print(-1)
            break
        else:
            ans[s-1]=c
            temp[s-1]=s-1
    elif temp[s-1]!=0 and ans[s-1]!=c:
        print(-1)
        break
else:
    if ans[0]==0:
        ans[0]=1
    print(*ans,sep="")