from heapq import heappush, heappop

N, M = map(int, input().split())
graph = [[] for i in range(N)]
for i in range(1, N):
  graph[i].append((i-1, 0))

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

dist = [-1] * N
d = [(0, 0)]
while d:
  cost, node = heappop(d)
  if dist[node] >= 0:
    continue
  dist[node] = cost
  for child, c in graph[node]:
    if dist[child] >= 0:
      continue
    heappush(d, (cost+c, child))

print(dist[-1])