import math

N, M = map(int, input().split())
num = int(''.join(['9'] * N))

candidate = []
for i in range(1000):
    candidate.append(i)

for _ in range(M):
    s, c = map(int, input().split())
    tmp = []
    for n in candidate:
        if N != len(str(n)):
            continue
        if int(str(n)[s - 1]) == c:
            tmp.append(n)
    candidate = tmp

if candidate:
    print(candidate[0])
else:
    print(-1)