r, c, k = gets.split.map(&:to_i)
grid = Array.new(r) { Array.new(c) }
k.times do |i|
  ri, ci, vi = gets.split.map(&:to_i)
  grid[ri - 1][ci - 1] = vi
end

def max_a_b(a, b)
  a > b ? a : b
end

dp = (r + 1).times.map { (c + 1).times.map { Array.new(4) } }
r.times do |up_row|
  dp_up = dp[up_row]
  dp_current = dp[up_row + 1]
  current_grid = grid[up_row]
  c.times do |left_col|
    up_max = dp_up[left_col + 1][3] || 0
    dp_current_current = dp_current[left_col + 1]
    current_value = current_grid[left_col] || 0
    dp_current_left_col_0, dp_current_left_col_1, dp_current_left_col_2, dp_current_left_col_3 = dp_current[left_col]
    dp_current_current[0] = max_a_b(up_max, dp_current_left_col_0 || 0)
    max_when_slected_0 = max_a_b(up_max, dp_current_left_col_0 || 0)
    dp_current_current[1] = max_a_b(dp_current_left_col_1 || 0, max_when_slected_0 + current_value)
    max_when_selected_1 = max_a_b(up_max, dp_current_left_col_1 || 0)
    dp_current_current[2] = max_a_b(dp_current_left_col_2 || 0, max_when_selected_1 + current_value)
    max_when_selected_2 = max_a_b(up_max, dp_current_left_col_2 || 0)
    dp_current_current[3] = max_a_b(dp_current_left_col_3 || 0, max_when_selected_2 + current_value)
  end
end
puts dp.last.last.max
