

N, M = list(map(int, input().split()))
sol = [-1] * N
for i in range(M):
    s, c = list(map(int, input().split()))
    if sol[s-1] != -1 and sol[s-1] != c:
        print('-1')
        exit(0)
    sol[s-1] = c

for v in range(1, 1000):
    s = str(v)
    if len(s) != N:
        continue
    fail = False
    for i in range(len(sol)):
        if sol[i] == -1:
            continue
        if int(s[i]) != sol[i]:
            fail = True
            break
    if not fail:
        print(v)
        exit(0)
print(-1)
