N,M=(input()).split(" ")
N=(int)(N)
M=(int)(M)
sc={}

for i in range(N):
    sc[i]=-1

check=True

for i in range(M):
    s,c=(input()).split(" ")
    s=(int)(s)
    c=(int)(c)
    if sc[s-1]!=-1 and sc[s-1]!=c:
        check = False
        break
    else:
        sc[s-1]=c

if not(check):
    print(-1)
    exit()

if sc[0]!=0:
    

    ans=""
    if sc[0]==-1:
        ans+="1"
    else:
        ans+=str(sc[0])

    for i in range(N-1):
        if sc[i+1]==-1:
            ans+="0"
        else:
            ans+=str(sc[i+1])
    print(ans)
else:
    if N==1:
        print(0)
    else:
        print(-1)