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

r = [9 , 9, 9]

S = []

for _ in range(m):
    s, c = map(int,input().split())
    if r[s - 1] > c:
        r[s - 1] = c
    S.append(s)

for j in range(1, n + 1):
    if j not in S:
        r[j - 1] = 0


if r[0] == 0 and n == 3:
    print(-1)
    exit()

if r[1] == 0 and n == 2:
    print(-1)
    exit()

r = list(map(str, r))
if n == 1:
    print(r[2])
elif n == 2:
    print(r[1] + r[2])
elif n == 3:
    print(r[0]+ r[1] + r[2])
