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

c = []
# f = []
for i in range(N):
    c.append(0)
    # f.append(0)

for i in s:
    if c[i[0] - 1] == 0:
        c[i[0] - 1] = i[1]
        # f[i[0] - 1] = i[1]
    elif (c[i[0] - 1] > i[1]) and i[1] != 0:
        c[i[0] - 1] = i[1]
        # f[i[0] - 1] = i[1]

c = map(str, c)

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