from heapq import heappush, heappop
INF = 10**10
n,m=map(int,input().split())
graph=[[] for i in range(n)]
for i in range(m):
  l,r,c=map(int,input().split())
  l-=1;r-=1
  graph[l].append((r,c))
for i in range(n-1):
  graph[i+1].append((i,0))
def dijkstra(N, G, s):
    global dist
    dist = [INF] * N
    que = [(0, s)]
    dist[s] = 0
    while que:
        c, v = heappop(que)
        if dist[v] < c:
            continue
        for t, cost in G[v]:
            if dist[v] + cost < dist[t]:
                dist[t] = dist[v] + cost
                heappush(que, (dist[t], t))
dijkstra(n,graph,0)
print(dist[n-1])