import sys

N, M = map(int, input().split())
s = [0] * M
c = [0] * M
for i in range(M):
    s[i], c[i] = map(int, input().split())


for i in range(1000):
    S = str(i)

    if len(S) != N:
        continue

    for j in range(M):
        if int(S[s[j]-1]) != c[j]:
            break
        if j == M-1 and (N == 1 or int(S[0]) != 1):
            print(S)
            sys.exit()

print(-1)