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 = []
w.times do |j|
  a.push rck[0][j]
  a.sort!
  a.shift if a.size > 3
  dp[j] = a.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

    # val = [val, dp[i-1][j]].max if i > 0
    # if rck[i][j] > 0
    #   row3.push rck[i][j]
    # end
    # if row3.size > 3
    #   row3.sort!.reverse!
    #   row3.pop
    # end
    # dp[i][j] = val + row3.sum
  end
end

puts dp.last
