class Work
  def initialize
    @cost = 0
    @prev_node = nil
    @next_node = nil
  end

  def update_next_node
    cost = @prev_node.max_day + @cost
    @next_node.max_day = (@prev_node.max_day > cost ? @prev_node.max_day : cost)
  end

  attr_accessor :cost, :prev_node, :next_node
end

class Node
  def initialize
    @max_day = 0
    @prev_works = []
    @next_works = []
  end

  def update_max_day
    return if @next_works.size == 0
    @next_works.each do |work|
      work.update_next_node
    end
  end

  def prev_max
    max = 0
    unless @prev_works.size == 0
      @prev_works.each do |work|
        cost = work.cost + work.prev_node.max_day
        max = (max > cost ? max : cost)
      end
    end
    max
  end

  attr_accessor :max_day, :prev_works, :next_works
end

def main
  n,m = gets.chomp.split(' ').map(&:to_i)
  nodes = Array.new(n).map{Node.new}
  works = Array.new(m).map{Work.new}

  m.times do |i|
    a,b,c = gets.chomp.split(' ').map(&:to_i)
    works[i].prev_node = nodes[a]
    works[i].next_node = nodes[b]
    works[i].cost = c
    nodes[a].next_works << works[i]
    nodes[b].prev_works << works[i]
  end

  nodes.each do |node|
    node.update_max_day
  end
  puts nodes[-1].max_day
end

main