import sys
input=sys.stdin.readline
import heapq
n,m=map(int,input().split())

def dijkstra_heap(s):
  d=[float("inf")]*n
  used=[True]*n
  d[s]=0
  used[s]=False
  edgelist=[]
  for e in edge[s]:
    heapq.heappush(edgelist,e)
  while edgelist:
    minedge = heapq.heappop(edgelist)
    if not used[minedge[1]]:
      continue
    v = minedge[1]
    d[v] = minedge[0]
    used[v] = False
    for e in edge[v]:
      if used[e[1]]:
        heapq.heappush(edgelist,[e[0]+d[v],e[1]])
  return d
edge = [[] for i in range(n)]
for i in range(m):
  l,r,c=map(int,input().split())
  edge[l-1].append([c,r-1])
for i in range(1,n):
  edge[i].append([0,i-1])


d=dijkstra_heap(0)
print(-1 if d[-1]==float("inf") else d[-1])


  