n, m = map(int, input().split())
sc = []
for i in range(m):
    sc.append(list(map(int, input().split())))
ans = 0
s = set()
keta = set()
for i in range(m):
    preans = sc[i][1]*(10**(n-sc[i][0]))
    if sc[i][0] in keta and preans not in s:
        print(-1)
        break
    elif sc[i][0]  not in keta:
        ans += preans
        s.add(preans)
        keta.add(sc[i][0])
else:
    if n not in keta::
        print(ans + 10**(n-1))
    elif len(str(ans)) == n:
        print(ans)
    else:
        print(-1)
