from heapq import heappush, heappop
def dijkstra(s,n,dic):
  q = [(0,s)]
  dist = [10**20]*n
  dist[s] = 0
  while q:
    v,p = heappop(q)
    if dist[p]<v:
      continue
    for e,c in dic[p]:
      if dist[e]>dist[p]+c:
        dist[e] = dist[p]+c
        heappush(q,(dist[e],e))
  return dist
N, M, *L = map(int, open(0).read().split())
Els = [[] for i in range(N+1)]
for i in range(2,N+1):
  Els[i].append((i-1,0))
for l,r,c in zip(*[iter(L)]*3):
  Els[l].append((r,c))
  
dist = dijkstra(1,N+1,Els)
if dist[N]==10**20:
  print(-1)
else:
  print(dist[N])