N, M = map(int, input().split())
num = [0] * N
for i in range(M):
    s, c = map(int, input().split())
    if num[s-1] == 0:
        num[s-1] = c
        continue
    if i > 1 and num[s-1] != 0 and c == 0:
        continue
    num[s-1] = min(num[s-1], c)

print([-1, "".join(map(str, num))][num[0] != 0])
