GC.disable

(R, C, K), *RCVs = readlines.map{_1.split.map(&:to_i)}

a = RCVs.each_with_object(Array.new(R + 1){Array.new(C + 1, nil)}){|(r, c, v), a| a[r][c] = v}
dp, dp1 = Array.new(C + 2){Array.new(4, 0)}, Array.new(C + 2){Array.new(4, 0)}
(1 .. R).each do |i|
  (1 .. C).each do |j|
    v = a[i][j]
    3.downto(1){|k| dp[j][k] = dp[j][k - 1] + v if dp[j][k] < dp[j][k - 1] + v} if v
    dp1[j][0] = dp[j].max
    dp[j + 1][0] = dp[j][0] if dp[j + 1][0] < dp[j][0]
    dp[j + 1][1, 3] = dp[j][1, 3]
  end
  dp, dp1 = dp1, dp
end
puts dp[C][0]