import math
import string


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//math.factorial(n-r)*math.factorial(r)


n, m = map(int, input().split())
sc = [input().split() for i in range(m)]
# print(sc)
# print(len(sc))
if len(sc) == 1:
    print(-1)
    exit()

for i in range(m):
    if (sc[0][0] == sc[i][0])and(sc[0][1] != sc[i][1]):
        print(-1)
        exit()

#print(sorted(set(list(map(tuple, sc)))))
x = sorted(set(list(map(tuple, sc))))
# print(len(x))
# print(x[0][0])
for i in range(len(x)):
    if int(x[i][0]) == 1:
        h = 100*int(x[i][1])
        print(h)
    elif int(x[i][0]) == 2:
        i = 10*int(x[i][1])
        print(i)
    elif int(x[i][0]) == 3:
        j = 1*int(x[i][1])
        print(j)
print(h+i+j-1)
