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

t = ''
for i in range(1, n + 1):
    if i not in r:
        t += '0'
    else:
        t += str(r[i])

a = int(t)

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