n, m = map(int, input().split())
sc = [map(int, input().split()) for _ in range(m)]

number = [-1] * n
for s, c in sc:
    if number[s - 1] < 0:
        number[s - 1] = c
    elif number[s - 1] != c:
        print(-1)
        exit()

res = 0
for i in range(n):
    if number[i] >= 0:
        res += number[i] * 10 ** (n - i - 1)

if len(str(res)) == n:
    print(res)
else:
    print(-1)
