n,m=[int(i) for i in input().split()]
keta=[-1 for i in range(n)]
flg=True
for i in range(m):
    s,c=[int(j) for j in input().split()]
    if keta[s-1]!=-1 and keta[s-1]!=c:
        flg=False
        break
    keta[s-1]=c
if flg:
    for i in range(n):
        if keta[i]==-1:
            keta[i]=0
    if keta[0]==0 and n>1:
        print(-1)
    else:
        print(*keta,sep="")
else:
    print(-1)