n,m=map(int,input().split())
o=[list(map(int,input().split()))for i in range(m)]
ans=-1
for i in range(10**n):
    c=0
    for j in o:
        if (i//(10**(n-j[0])))%10==j[1] and len(str(i))==n:
            c+=1
    if c==m:ans=i;break
print(ans)
