n,m = map(int,input().split())
lrc = []
for _ in range(m):
  lrc.append(list(map(int,input().split())))
import heapq
heapq.heapify(lrc)
arrive = [[1,0]]
heapq.heapify(arrive)
#print(arrive)
try:
  while True:
    point,dis = heapq.heappop(arrive)
    if point == n:
      print(dis)
      break
    if arrive != []:
      if dis >= arrive[0][1]:
        continue
    while True:
      if lrc == []:
        break
      if lrc[0][0] <= point:
        l,r,c = heapq.heappop(lrc)
        if r > point:
          heapq.heappush(arrive,[r,dis+c])
      else:
        break
except:
  print(-1)