import heapq

N, M = map(int,input().split())

V = N
G = [[] for _ in range(V)]    #[[to, cost], [], ...]
s = 0

INF = float('inf')

for i in range(V-1):
    G[i+1].append([i, 0])

for _ in range(M):
    l, r, c = map(int,input().split())
    G[l-1].append([r-1, c])

def dijkstra(s):			#始点sからの最短距離のリストを返す
    d = [INF for _ in range(V)]
    d[s] = 0
    que = []
    heapq.heappush(que, (0, s))
    
    while len(que) != 0:
        p = heapq.heappop(que)
        v = p[1]
        if d[v] < p[0]:
            continue
        for i in range(len(G[v])):
            e = G[v][i]
            if d[e[0]] > d[v] + e[1]:
                d[e[0]] = d[v] + e[1]
                heapq.heappush(que, (d[e[0]], e[0]))

    return d

L = dijkstra(s)

print(L[N-1])