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

Q = [list(map(int, input().split())) for _ in range(M)]

for i in range(10 ** (N - 1), 10 ** N):
    t = list(str(i))

    f = True
    for s, c in Q:
        f &= t[s - 1] == str(c)

    if f:
        print(i)
        exit()

if N == 1:
    f = True
    for _, c in Q:
        f &= c == 0

    if f:
        print(0)
        exit()

print(-1)
