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(0)
flg = True
for i in s:
    if i[0] - 1 == 0 and i[1] == 0 and N != 1:
        flg = False
    if (c[i[0] - 1] != 0) and c[i[0] - 1] != i[1]:
        flg = False
    c[i[0] - 1] = i[1]

c = map(str, c)
d = ''.join(c)

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