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