n,m = gets.split.map &:to_i

a = []
c_d = {}

c_d[0] = 1

m.times do |i|
    l,r,c = gets.split.map &:to_i
    a << [l,r,c]
end

min_cost = nil

a.sort.each do |ai|
    copy = c_d.dup
    c_d.each do |current_cost, current_distance|
        if current_distance >= ai[0]
            copy[current_cost + ai[2]] = [current_distance, ai[1], copy[current_cost + ai[2]].to_i].max
            if ai[1] == n
                min_cost ||= current_cost + ai[2]
                min_cost = [min_cost, current_cost + ai[2]].min
            end
        end
    end
    c_d = copy
end

if min_cost
    puts min_cost
else
    puts -1
end

