n, m = map(int, input().split())

s1 = 0
s2 = 0
s3 = 0

r = {'1': 0, '2': 0, '3': 0}
for i in range(m):
    s, c = input().split()
    c = int(c)
    if r[s] == 0:
        r[s] = c
    if r[s] > c:
        r[s] = c

a = int('{}{}{}'.format(r['1'], r['2'], r['3']))

if (n == 1 and 1 <= a < 10) or \
   (n == 2 and 10 <= a < 100) or \
   (n == 3 and 100 <= a <= 1000):
    print(a)
else:
    print('-1')