N,M=map(int,input().split())
S=[list(map(int,input().split())) for _ in range(M)]

for i in range(10**(N-1),10**N):
    letter=str(i)
    for j in range(M):
        if letter[S[j][0]-1]!=str(S[j][1]):
            break
    else:
        print(i)
        break
else:
    print('-1')