#12:00
#解説解答
n,m = map(int,input().split())
inf = 10 ** 18
pst = [[] for _ in range(n)]
for i in range(1,n):
  pst[i].append([0,i-1])
for _ in range(m):
  l,r,c = map(int,input().split())
  l -= 1
  r -= 1
  pst[l].append([c,r])
#print(pst)
import heapq
nxt = pst[0]
heapq.heapify(nxt)
#print(nxt)
seen = [inf for _ in range(n)]
seen[0] = 0
for x in nxt:
  seen[x[1]] = x[0]
while True:
  #print(nxt)
  if nxt == []:
    print(-1)
    break
  c,r = heapq.heappop(nxt)
  if r == n-1:
    print(seen[r])
    break
  for x in pst[r]:
    #print(pst[r])
    #print(x)
    xc,xr = x
    if seen[xr] > seen[r] + xc:
      seen[xr] = seen[r] + xc
      heapq.heappush(nxt,[seen[xr],xr])
#print(seen)