import re

N, M = map(int, input().split())
# print("N:", N, "M:", M)
s = [list(map(int, input().split())) for _ in range(M)]
s.sort()
# print(s)

c = []
for i in range(N):
    c.append('x')

for i in s:
    # print("c:", c, " i:", i, " c[i[0] - 1]:", c[i[0] - 1])
    if i[0] - 1 == 0 and i[1] == 0:
        pass
    elif (c[i[0] - 1] == 'x') or (c[i[0] - 1] > i[1]):
        c[i[0] - 1] = i[1]

c = map(str, c)

d = ''.join(c)
re.sub('x', '0', d)
# print("d:", d)
if (d[:1] == "0") and (N != 1):
    print("-1")
else:
    print(d)