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

command = []

ANS = -1

for i in range(m):
    s, c = input().split()
    command.append([s, c])

for i in range(1, 10**n + 1):
    count = 0
    for j in command:
        if len(str(i)) >= int(j[0]):
            if str(i)[int(j[0]) - 1] == j[1]:
                count += 1
        else:
            pass
    if count == m:
        ANS = i
        break

print(ANS)