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

if N == 1:
    st = 0
    fin = 10
elif N == 2:
    st = 10
    fin = 100
else:
    st = 100
    fin = 1000
for i in range(st,fin):
    moji = str(i)
    for j in range(M):
        if (int(moji[S[j]-1]) != C[j]):
            break
        if j == M-1:
            print(i)
            exit()

print(-1)
