N,M=map(int,input().split())
keta=[]
for i in range(N):
    keta.append('x')
ans=-1
for _ in range(M):
    si,ci=input().split()
    si=int(si)
    if keta[si-1]=='x':
        keta[si-1]=ci
    else:
        if keta[si-1]!=ci:
            break
else:
    if keta[0]=='0' and N!=1:#先頭要素が０かつ2桁以上の数なら
        print(-1)
        exit()
    
    if keta[0]=='x' and N==1:
        print(0)
        exit()
    if keta[0]=='x' and N>=2:
        keta[0]=1
    for i in range(1,3):
        if keta[i]=='x':
            keta[i]='0'

    ans=int(''.join(keta))

print(ans)

