import strutils,sequtils,math,algorithm
template rep(a,b):seq = newSeqWith(b,a)
when true:
  #type HeapQueue {.importcpp:"std::priority_queue", header:"<queue>".} [T] = object
  #proc initHeapQueue[T]:HeapQueue[T] {.importcpp:"std::priority_queue<'*0>()", nodecl.}
  type HeapQueue {.importcpp:"std::priority_queue<'0,std::vector<'0>,std::greater<'0> >", header:"<queue>".} [T] = object
  proc initHeapQueue[T]:HeapQueue[T] {.importcpp:"std::priority_queue<'*0,std::vector<'*0>,std::greater<'*0> >()", nodecl.}
  proc len[T](q:HeapQueue[T]):int {.importcpp:"size", nodecl.}
  proc push[T](q:var HeapQueue[T],x:T) {.importcpp:"push", nodecl.}
  proc cPop[T](q:var HeapQueue[T]) {.importcpp:"pop", nodecl.}
  proc cTop[T](q:HeapQueue[T]):T {.importcpp:"top", nodecl.}
  template pop[T](q:var HeapQueue[T]):T = (let t=q.cTop; q.cPop; t)
  type Pair {.importcpp:"std::pair"} [S,T] = object
  proc pair[S,T](a:S; b:T):Pair[S,T] {.importcpp:"std::make_pair(@)", nodecl.}
  proc fst[S,T](p:Pair[S,T]):S {.importcpp:"#.first", nodecl.}
  proc snd[S,T](p:Pair[S,T]):T {.importcpp:"#.second", nodecl.}
  converter toTuple[S,T](p:Pair[S,T]):tuple[a:S;b:T] = (p.fst,p.snd)
proc distFrom(aj:seq[seq[tuple[to,co:int]]]; s:int): seq[int] =
  let n = aj.len
  var d = (1 shl 30).repeat n; d[s] = 0
  var q = initHeapQueue[Pair[int,int]]()
  for v in 0..<n: q.push(pair(d[v],v))
  while q.len > 0:
    let (dv,v) = q.pop.toTuple
    for e in aj[v]:
      let nd = dv + e.co
      if d[e.to] > nd:
        d[e.to] = nd
        q.push(pair(nd,e.to))
  return d.mapIt(if it == 1 shl 30: -1 else: it)
proc solve(N,M:int; LRC:seq[tuple[L,R,C:int]]) =
  var aj=newSeq[tuple[to,co:int]]().repeat N
  for e in LRC:
    aj[e.L-1].add((to:e.R-1,co:e.C))
  for i in 1..<N:
    aj[i].add((to:i-1,co:0))
  let d=aj.distFrom 0
  echo d[^1]

when isMainModule:
  let get = iterator:string {.closure.} = 
    for s in stdin.readAll.split: yield s
  let N,M = get().parseInt
  let LRC = rep((L:get().parseInt,R:get().parseInt,C:get().parseInt), M)
  solve(N,M,LRC)