nm = input()
n, m = nm.split(' ')

data = []
for i in range(int(m)):
    tmp = input()
    n1, n2 = tmp.split(' ')
    data.append([int(n1), int(n2)])

ans = {}

for target in data:
    if target[0] not in ans.keys():
        ans[target[0]] = target[1]
    elif ans[target[0]] is not target[1]:
        print(-1)
        exit(1)

if ans[1] is 0:
    print(-1)
    exit(1)

keys = ans.keys()

res = 0
for key in keys:
    tmp = 10 ** (int(n) - int(key))
    a = tmp *  int(ans[key])
    res += a

print(res)
