import copy
import numpy as np
N, M = map(int, input().split())

A = []
for i in range(M):
    A.append(list(map(int, input().split())))

A = np.array(A)
A_1 = A[:, 0]
arg_A_1 = np.argsort(A_1)
new_A = A[arg_A_1]
# print(A, A_1, arg_A_1, new_A)

INF = 10**9 + 1
dp = [INF] * N
dp[0] = 0
for i in range(M):
    tmp = new_A[i]
    left = tmp[0]-1
    right = tmp[1]

    for now_l in range(left, right):
        for now_r in range(now_l+1, right):
            # print(tmp[2], now_l, now_r)
            dp[now_r] = min(dp[now_l] + tmp[2], dp[now_r])
if dp[N-1]==INF:
    print(-1)
else:
    print(dp[N-1])
