from collections import defaultdict

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

number = defaultdict(int)
for s, c in sc:
    if s in number and c != number[s]:
        print(-1)
        exit()
    number[s] = c

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

if res == 0:
    print(0)
elif res < 10 ** (n - 1):
    print(-1)
else:
    print(res)
