N,M = map(int,input().split())
sc = [list(map(int,input().split())) for i in range(M)]
for i in range(10**N):
    stop = True
    for t in sc:
        if i//(10**(N-t[0]))%10 != t[1]:
            stop = False
    if stop:
        print(i)
        break
if stop:
    print(-1)
