N, M = list(map(int, input().split(' ')))
sc = [list(map(int, input().split(' '))) for i in range(M)]


ans_l = [0 for i in range(N)]

ans_final = 0

for s, c in sc:
    if (not ans_l[s-1]) or ans_l[s-1] == str(c):
        ans_l[s-1] = str(c)
    else:
        ans_final = -1
        break

ans_l = list(map(str, ans_l))

ans_n = 0

if not ans_final:
    ans_n = int(''.join(ans_l))

ans_final = ans_n
if len(str(ans_n)) != n:
    ans_final = -1

print(str(ans_final))