N, M = map(int, input().split())

lst = [list(map(int, input().split())) for _ in range(M)]
lst.sort(key=lambda x: x[0])

n = 10 ** N

for i in range(n - 1):
    moji = str(i)
    k = len(moji)

    if k != N:
        continue

    flag = True

    for s, c in lst:
        if s > k or moji[s - 1] != str(c):
            flag = False
            break

    if flag:
        print(str(i))
        exit()

print('-1')
