import sys

n = list(map(int, input().split()))
b = [list(map(int, input().split())) for i in range(n[1])]
keta = n[0]
ans = [0] * keta

for target_list in b:
    if ans[target_list[0] - 1] == 0:
        ans[target_list[0] -1] = target_list[1]
    elif ans[target_list[0] - 1] > target_list[1]:
        ans[target_list[0] -1] = target_list[1]
    else:
        pass
        
for target_list in range(keta):
    if ans[target_list] == 0:
        print("-1")
        sys.exit()
    else:
        break

print("".join(map(str,ans)))

