import numpy as np

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

max = 10 ** N - 1

smax = np.max(s)
if smax != 1:
    min = 10 ** (smax - 1)
else:
    min = 0

answer = -1
for i in range(max, min-1, -1):
    flag = 1
    for j in range(M):
        if int(str(i)[s[j]-1]) != c[j]:
            flag = 0
    if flag == 1:
        answer = i
print(answer)