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

for i in range(1000):
    answer = str(i)
    if len(answer) == N and all( answer[s-1]==str(c) for s,c in SC):
        print(i)
        exit(0)

print(-1)