import sys
from heapq import heappop, heappush

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))
    
    front = []
    heappush(front, (0, 0))
    while heap:
        l, r, c = heappop(heap)

        front_ = []
        while front:
            r_, c_ = heappop(front)
            if r_ < l:
                continue
            
            heappush(front_, (r_, c_))
            heappush(front_, (r, c+c_))
            if r == N-1:
                ans = min(ans, c+c_)
        
        front = front_
            
    if ans == INF:
        return -1
    
    return ans

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