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 = str(int(''.join([str(number[i + 1]) for i in range(n)])))

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