N, M = map(int, input().split())
S = []
C = []
for _ in range(M):
    s, c = map(int, input().split())
    S.append(s)
    C.append(c)
number_list = [10]*N

for i in range(M):
    if number_list[S[i]-1] > C[i]:
        number_list[S[i]-1] = C[i]

number_list = [0 if i==10 else i for i in number_list ]

if N == 3 and number_list[0] == 0:
    answer = -1
elif N == 2 and number_list[1] == 0:
    answer = -1
elif N == 1 and number_list[2] == 0:
    answer = -1
else:
    answer = ''.join(map(str,number_list))    

print(answer)