N, M = map(int, input().split())
S = []
C = []
result = ''
for i in range(M):
    a, b = map(int, input().split())
    S.append(a)
    C.append(b)

if 1 in S:
    x = S.index(1)
    result += str(C[x])
    if C[x] != 0:

        if 2 in S:
            y = S.index(2)
            result += str(C[y])

        else:
            result += '0'

        if 3 in S:
            z = S.index(3)
            result += str(C[z])
        else:
            result += '0'
    else:
        result = -1
else:
    result = -1

print(result)