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]*3
answer=0

for i in range(M):
    if C[i] == 0 and N != 1:
        continue
    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 ]

for i in range(N):
    answer += number_list[i]*10**(N-i-1)

if number_list[0] == 0 and N != 1:
    answer = -1

print(answer)