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'
for s, c in l:
    if keta_list[s-1] == 0:
        keta_list[s-1] = c
    elif keta_list[s-1] != 0 and keta_list[s-1] != c:
        print('-1')
        sys.exit()
if keta_list[0] == 0:
    print('-1')
    sys.exit()
ans = int(''.join(map(str, keta_list)))
print(ans)