import itertools
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())

numlist = ['0','1','2','3','4','5','6','7','8','9']

for num in itertools.product(numlist, repeat=3):
    if len(str(int(''.join(num)))) == N:
        for s, c in zip(S, C): 
            if num[s-1] == str(c):
                ans = int(''.join(num))
            else:
                ans = -1
                break
        if ans != -1:
            break

print(ans)
