r,c,k = gets.split.map(&:to_i)
z=[]
for i in 0...k
  tmp = gets.split.map(&:to_i)
  if tmp[2]>0
    z.push(tmp)
  end
end

score = Array.new(r){Array.new(c,0)}
z.each do |i|
    score[i[0]-1][i[1]-1] = i[2]
end

m_score = Array.new(r){Array.new(c,0)}

for i in 0...r
  kouho = []
  for j in 0...c
    if score[i][j]>0
      m_score[i][j] += score[i][j]
      kouho.push(score[i][j])
      if kouho.size==4
        kouho = kouho.sort
        m_score[i][j] -= kouho[0]
        kouho.shift(1)
      end
    end
    
    if i+j==0
      next
    elsif i==0
      m_score[i][j] += m_score[i][j-1]
    elsif j==0
      m_score[i][j] += m_score[i-1][j]
    else
      m_score[i][j] += [m_score[i][j-1],m_score[i-1][j]].max
    end
  end
end

puts m_score[r-1][c-1]
