N,M=map(int,input().split())
SC=[list(map(int,input().split())) for i in range(M)]
r=-1
for i in range(10**N):
    n=str(i)
    l=len(n)
    if l!=N:
        continue
    f=1
    for s,c in SC:
        if not (s<=l and n[s-1]==str(c)):
            f=0
    if f==1:
        r=i
        break
print(r)