n, m = map(int, input().split())
ans = ['-1'] * n

no = 0
for i in range(m):
    a, b = map(int, input().split())
    a -= 1
    if ans[a] != '-1':
        if ans[a] != str(b):
            no = 1
    ans[a] = str(b)

if no:
    print(-1)
    exit()
# print(ans)
ansstr = "".join(ans)
an = ansstr.replace('-1', '0')

if len(ans) > 1:
    if an[0] == '0':
        print(-1)
        exit()
print(an)
