N, M = map(int, input().split())
ans = -1
S = [0] * M
C = [0] * M
for i in range(M):
    S[i], C[i] = map(int, input().split())

for i in range(1,10**N+1):
    if len(str(i)) == N:
        for s, c in zip(S, C):
            if str(i)[s-1] == str(c):
                ans = i
            else:
                ans = -1
                break
        if ans != -1:
            break
print(ans)