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]))

dp = np.full(N+1, 10**6)
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] < 10**6:
    print(dp[-1])
else:
    print(-1)