N, M = map(int, input().split())
number = [0 for i in range(N)]
judge = []


for i in range(M):
    keta, num = map(int, input().split())
    keta -= 1
    judge.append(keta)

    if (len(judge) != len(set(judge))):
        ans = -1
    else:
        number[keta] = num

if (number[0] == 0):
    ans = -1
else:
    ans = str(number[0]) + str(number[1]) + str(number[2])
    ans=int(ans)

print(ans)