from itertools import *



n, m = map(int, input().split())
# nedd = [str(i) for i in range(1, 1000) if len(str(i)) == n]
inp = []
for i in range(m):
    i, v = map(int, input().split())
    inp.append([i, v])
p = []
for i in inp:
    p.append(i[0])
for i in range(1, m+1):
    if i not in p:
        inp.append([i, 0])
inp.sort()
num = [i[1] for i in inp]
ans = []
for i in combinations(num, n):
    ans.append("".join(map(str, list(i))))
ans = sorted(ans, key=lambda i: int(i))
for i in ans:
    if len(i) == n:
        print(i)
        break
else:
    print(-1)