import sys
input = sys.stdin.readline
sys.setrecursionlimit(pow(10, 6))

from heapq import heappop, heappush


def main():
    n, m = map(int, input().split())
    edges = [[] for _ in range(n)]
    for i in range(1, n):
        edges[i] = [(i - 1, 0)]
    
    lrc = [tuple(map(int, input().split())) for _ in range(m)]
    for l, r, c in lrc:
        edges[l - 1].append((r - 1, c))

    d = [float("inf") for _ in range(n)]
    d[0] = 0
    h = [(0, 0)]
    while len(h) > 0:
        tmpd, tmpi = heappop(h)
        for toi, tod in edges[tmpi]:
            if d[toi] > tmpd + tod:
                d[toi] = tmpd + tod
                heappush(h, (d[toi], toi))
    
    if d[n - 1] == float("inf"):
        print(-1)
    else:
        print(d[n - 1])
    


if __name__ == '__main__':
    main()
