N, M = map(int, input().split())
sc = [list(map(int, input().split())) for _ in range(M)]
for i in range(10**N):
    a = str(i)
    if len(a) == N and all(str(a[s-1]) == str(c) for s,c in sc):
        print(i)
        exit()
print(-1)