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

for i in range(1000):
    n = str(i)
    if len(n) == N:
        if all( n[s-1] == str(c) for s,c in A):
            print(i)
            break
else:
    print(-1)