import heapq
N,M=map(int,input().split())
path=[[0 if i==j or i==max(j-1,0) else float("inf") for i in range(N)] for j in range(N)]
for _ in range(M):
  l,r,c=map(int,input().split())
  path[l-1][r-1]=c

dist=[float("inf")]*N
dist[0]=0
q=[[dist[i],i] for i in range(N)]
heapq.heapify(q)

while q:
  d,ind=heapq.heappop(q)
  if d<=dist[ind]:
    for i in range(N):
      if dist[i]>d+path[ind][i]:
        dist[i]=d+path[ind][i]
        heapq.heappush(q,[dist[i],i])

if dist[N-1]==float("inf"):
  print(-1)
else:
  print(dist[N-1])
