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

a = RCVs.each_with_object(Array.new(R + 1){Array.new(C + 1, 0)}){|(r, c, v), a| a[r][c] = v}
ma = ->(a, b){a > b ? a : b}
dp = Array.new(R + 1){Array.new(C + 1){Array.new(4, 0)}}
(0 .. R).each do |r|
  (0 .. C).each do |c|
    (0 .. 3).each do |k|
      if r >= 1
        dp[r][c][0] = ma[dp[r][c][0], dp[r - 1][c][k]]
        dp[r][c][1] = ma[dp[r][c][1], dp[r - 1][c][k] + a[r][c]]
      end
      if c >= 1
        dp[r][c][k] = ma[dp[r][c][k], dp[r][c - 1][k]]
        dp[r][c][k] = ma[dp[r][c][k], dp[r][c - 1][k - 1] + a[r][c]] if k > 1
      end
    end
  end
end
puts dp[R][C].max