import sys
n, m = map(int, input().split())
l = [list(map(int, input().split())) for i in range(m)]
keta_list = [0] * n
ans = '-1'
if m > 0:
    for s, c in l:
        if keta_list[s-1] == 0:
            keta_list[s-1] = c
        elif keta_list[s-1] != 0 and c < keta_list[s-1]:
            keta_list[s-1] = c
ans = int(''.join(map(str, keta_list)))
if len(str(ans)) < n:
    ans = '-1'
print(ans)