require 'set'; require 'prime'; require 'pp'
INF=Float::INFINITY; MOD=10**9+7
h,w,k = gets.chomp.split.map(&:to_i)
rck = Array.new(h){Array.new(w, 0)}
k.times do
  r,c,v = gets.chomp.split.map(&:to_i)
  rck[r-1][c-1] = v
end

dp = Array.new(w, 0)
a = []
sum = 0
w.times do |j|
  rckj = rck[0][j]
  a.push rckj
  sum += rckj
  size = a.size
  i = size - 1
  while i > 0 && a[i-1] < a[i]
    a[i-1], a[i] = a[i], a[i-1]
    i -= 1
  end
  if size > 3
    sum -= a.pop
  end
  dp[j] = sum
end
# p dp

1.upto(h-1) do |i|
  3.times do |k|
    dp2 = Array.new(w, 0)
    w.times do |j|
      if j == 0 && k == 0
        dp2[j] = dp[j] + rck[i][j]
      elsif j < k
        dp2[j] = dp[j]
      else
        if k == 0
          dp2[j] = [dp[j], dp2[j-1], dp[j] + rck[i][j]].max
        else
          dp2[j] = [dp[j], dp2[j-1], dp[j-1] + rck[i][j]].max
        end
      end
    end
    dp = dp2
    # p dp
  end
end

puts dp.last