import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def dijkstra(s,n,w,cost):
  #始点sから各頂点への最短距離
  #n:頂点数,　w:辺の数, cost[u][v] : 辺uvのコスト(存在しないときはinf)
  d=[inf] * n
  used=[False] * n
  d[s]=0
  
  while True:
    v=-1
    #まだ使われてない頂点の中から最小の距離のものを探す
    for i in range(n):
      if (not used[i]) and (v == -1):
        v = i
      elif (not used[i]) and d[i] < d[v]:
        v = i
    if v == -1:
      break
    used[v] = True
           
    for j in range(n):
      d[j] = min(d[j],d[v]+cost[v][j])
  return d

def main():
  n,m=LI()
  cost=[[inf for i in range(n)] for i in range(n)]

  for i in range(m):
    l,r,c=LI()
    for i in range(l-1,r-1):
      for j in range(i+1,r):
        cost[i][j]=min(cost[i][j],c)

  ans=dijkstra(0,n,m,cost)
  if ans[-1]==inf:
    return -1
  return ans[-1]

# main()
print(main())
