import numpy as np

n, m = list(map(int, input().split(' ')))
s = [list(map(int, input().split(' ')))
     for _ in range(m)]
s = np.array(s)
s = np.unique(s, axis=0)

output = 0
for _s in s:
    output += 10**(n-_s[0]) * _s[1]

if len(s) != len(np.unique(s[:, 0])) or output == 0:
    output = -1

print(output)