nm = list(map(int, input().split()))
if nm[0] != nm[1]:
    print(-1)
    exit()

nm = int(nm[1])


nmi = []
for i in range(nm):
    nmi.append(list(map(int, input().split())))
ans = 0

count_max = []
for i in nmi:
    count_max.append(i[0])
n_max = max(count_max)

count_n = []
check = []
for i in nmi:
    if i[0] in check:
        for i2 in count_n:
            if i[1] != i2[1]:
                print(-1)
                exit()
    else:
        ans = ans + (i[1] * 10 ** (n_max - i[0]))
        count_n.append(i)
        check.append(i[0])

#以上のはずだけど問題の出力例が「より上」になってるから仕方なく
if ans >= 0:
    print(ans)
else:
    print(-1)
