import sys

read = sys.stdin.read
readline = sys.stdin.readline

N, M, *sc = map(int, read().split())
answer = [-1] * N

for s, c in zip(*[iter(sc)] * 2):
    s -= 1
    if answer[s] == -1:
        answer[s] = c
    else:
        if answer[s] != c:
            print(-1)
            exit()

if answer[0] == -1:
    answer[0] = 1
elif answer[0] == 0:
    print(-1)
    exit()

answer = [i if i != -1 else 0 for i in answer]
print(''.join(map(str, answer)))
