n,m=gets.split.map(&:to_i)
lrc=[]
m.times do |i|
  lrc << gets.split.map(&:to_i)
end
lrc.sort!
dp=[nil]*n
dp[0]=0
lrc.each do |l,r,c|
  if dp[l-1]==nil
    puts "-1"
    exit
  end
  l.upto(r-1) do |i|
    q=dp[l-1]+c
    if dp[i]==nil
      dp[i]=q
    elsif dp[i]>q
      dp[i]=q
    end
  end
end
puts dp[-1]
p dp