#author: dokueki

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()
# print(inp)
num = [i[1] for i in inp]
ans = []
c = 0
for i in combinations(num, n):
    ans.append("".join(map(str, list(i))))
# for i in range(len(ans)):
#     for j in range(n):
#         print(ans[i][j], end="")
#     print("\n")
ultimate = []
visit = set()
for i in range(len(ans)):
    for j in range(n):
        grab = [j+1, int(ans[i][j])]

        if grab in inp and (j+1) not in visit:
            # print(grab)
            c += 1
            visit.add(j+1)
            # print(c)
    if c == n:
        ultimate.append(ans[i])
        c = 0
        visit = set()
# print(ultimate)
ultimate = sorted(ultimate, key=lambda i: int(i))
for i in ultimate:
    if len(str(int(i))) == n:
        print(i)
        break
else:
    print(-1)
