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 = sum([number[i + 1] * 10 ** (n - i - 1) for i in range(n)])

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