import sys
from heapq import heappop, heappush
import numpy as np

def main():
    input = sys.stdin.readline
    INF = 10**15
    ans = INF
    N, M = map(int, input().split())
    heap = []
    for _ in range(M):
        l, r, c = map(int, input().split())
        heappush(heap, (l-1, r-1, c))
    
    dp = np.array([INF]*N, dtype=int)
    dp[0] = 0

    while heap:
        l, r, c = heappop(heap)
        s = dp[l]
        d = np.where(dp[l+1:r+1] < s+c, dp[l+1:r+1], s+c)
        dp[l+1:r+1] = d
            
    if dp[N-1] == INF:
        return -1
    
    return dp[N-1]

if __name__ == '__main__':
    print(main())