n,m=map(int,input().split())
sc=[list(map(int,input().split())) for i in range(m)]

ans=-1
for i in range(1000):
    moji=str(i)
    if(len(moji)!=n):continue
    for s,c in sc:
        if(moji[s-1]!=str(c)):break
    else:
        ans=i
        break
print(ans)