import sys
from operator import itemgetter
import numpy as np
read = sys.stdin.read

N, M, *LRC = map(int, read().split())
dp = np.full(N + 1, np.inf)
dp[1] = 0

for L, R, C in sorted(list(zip(*[iter(LRC)] * 3)), key=itemgetter(0, 1)):
    dp[L + 1:R + 1] = np.minimum(dp[L + 1:R + 1], dp[L] + C)
    dp[L + 1:R + 1] = np.minimum(dp[L + 1:R + 1], np.minimum.accumulate(dp[L + 1:R + 1] + C))

if dp[N] == np.inf:
    print(-1)
else:
    print(int(dp[N]))