N,M = map(int, input().split())
sets = []
for i in range(M):
    s,c = input().split()
    sets.append((s,c))
for n in range(10**(N-1), 10**N):
    for s,c in sets:
        if not str(n)[int(s)-1] == c:
            break
        else:
            print(n)
    break
else:
    print(-1)