import sys

n, m = map(int, input().split())
rules = [input().split() for _ in range(m)]
r = lambda n, s, c: n[int(s)-1] == c

for i in range(10 ** n):
    n = str(i)
    f = True
    for rule in rules:
        s, c = rule
        f = f and len(n) >= int(s) and r(n, int(s), c)
    if f:
        print(n)
        sys.exit()
print(-1)
