N,M=map(int,input().split())
sc=[list(map(int,input().split())) for _ in range(M)]
st=0 if N==1 else 10 if N==2 else 100
for n in range(st, 10**N):
    for i, (s, c) in enumerate(sc):
        if str(n)[s-1]==str(c):
            if (i+1)==M:
                print(n)
                exit()
            continue
        else:
            break
print(-1)
