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

c = []

c_append = c.append

for i in range(M):
    sm, cm = map(int, input().split())
    c_append((sm, cm))

ans = -1

# check
for i in range(1, 1000, 1):
    str_i = str(i)

    if N < len(str_i):
        break

    if N == len(str_i) and False not in [int(str_i[sm - 1]) == cm for sm, cm in c]:
        ans = i
        break

print(ans)