import numpy as np
N, M = map(int, input().split())
LRC = sorted([list(map(int, input().split())) for i in range(M)], key=lambda x: (x[0], x[1]))
 
inf = float('inf')
dp = np.full(N+1, inf)
dp[1] = 0
for l, r, c in LRC:
    dp[l:r+1] = np.minimum(dp[l:r+1], dp[l] + c)
 
if dp[-1] < inf:
    print(int(dp[-1]))
else:
    print(-1)