n,m=map(int,input().split())
l=[i for i in range(1000) if len(str(i))==n]
for i in range(m):
    s,c=map(int,input().split())
    l=[i for i in l if str(i)[s-1]==str(c)]
print(min(l) if l!=[] else -1)