import sys
N,M=map(int, sys.stdin.readline().split())
sc=[ map(int, sys.stdin.readline().split()) for _ in range(M) ]

if N==3: start,end=100,1000
elif N==2: start,end=10,100
elif N==1: start,end=0,10

for n in range(start,end):
    n=str(n)
    for s,c in sc:
        if n[s-1]==str(c):
            pass
        else:
            break
    else:
        print n
        quit()
else:
    print -1