n, m = input().split()

n = int(n)
m = int(m)

s = [0] * m
c = [0] * m
ans = ["0"] * n

han = True

for i in range(m):
    s, c = input().split()
    s = int(s)
    if ans[s-1] == "0" or ans[s-1] == c:
        ans[s-1] = c
    else:
        han = False
        break
anss = 0
for i in range(len(ans)):
    anss = anss + int(ans[i]) * 10 ** (n - 1 - i)
if (anss) % (10 ** (n - 1)) != 0 and han:
    print(anss)
else:
    print("-1")
