n,m=gets.split.map(&:to_i)
lrc=m.times.map{gets.split.map(&:to_i)}.sort
dp=[nil]*n
dp[0]=0
lrc.each do |l,r,c|
  if dp[l-1]==nil
    puts "-1"
    exit
  end
  q=dp[l-1]+c
  (r-1).downto(l) do |i|
    if dp[i]==nil||dp[i]>q
      dp[i]=q
    else
      break
    end
  end
end
puts dp[-1]
