n, m = map(int, input().split(' '))
sc = []
for i in range(m):
    a, b = map(int, input().split(' '))
    sc.append((a, b))
d = '0' * n
for i, j in sc:
    if d[i - 1] != '0' and int(d[i - 1]) != j:
        d = '-1'
        break
    d = d[:i - 1 if i > 1 else 0] + str(j) + d[i if i < 3 else 3:]
print(d if d[0] != '0' else '-1')