import sys
N, M = list(map(int, input().split()))

T = [-1] * N
ans = -1

for m in range(M):
    s, c = list(map(int, input().split()))
    s -= 1
    if T[s] != -1 and T[s] != c:
        print(-1)
        sys.exit(0)
    T[s] = c

if N == 1 and T[0] == -1:
    print(0)

for i in range(10**(N-1), 10**N):
    A = list(str(i))
    for n in range(N):
        if T[n] == -1:
            continue
        elif T[n] == int(A[n]):
            continue
        break
    else:
        print(i)
        sys.exit(0)

print(-1)
