n,m=map(int,input().split())
C=[[] for i in range(n)]
for i in range(m) :
    s,c=map(int,input().split())
    if s==1 and c==0 and n>1:
        print(-1)
        exit()
    C[s-1].append(c)

ans=[]
for i in range(n) :
    if C[i] :
        x=min(C[i])
        ans.append(str(x))
    elif not C[i] :
        x=0
        ans.append(str(x))
    else :
        print(-1)
        exit()

if ans[0]=="0" and n>1 :
    ans[0]="1"
    ans="".join(ans)
    print(ans)

else :
    print("".join(ans))
    