n,m=map(int, input().split())
sc = [list(map(int, input().split())) for x in range(m)]

ans = ['0']*(n+1)
ans[1] = '1'
flg = 0
for i in range(m):
    print(sc[i][1])
    if ans[sc[i][0]] == '0' or int(ans[sc[i][0]]) >= sc[i][1]:
        if sc[i][1] != 0 and flg == 0:
            ans[sc[i][0]] = str(sc[i][1])
            flg = 1
        else:
            continue
    else:
        continue
if ans[1] == '0' and len(ans) != 2:
    print(-1)
else:
    print(int(''.join(ans)))