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

r = {}
for i in range(m):
    s, c = map(int, input().split())
    c = int(c)
    if s not in r:
        r[s] = c
    if r[s] > c:
        r[s] = c

if i in range(1, 3):
    if i not in r:
        r[i] = 0

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')