R,C,K = gets.split.map &:to_i
RCV = K.times.map{ gets.split.map(&:to_i)}

rows = Array.new(R+1){[]}
RCV.each do |r,c,v|
    rows[r][c] = v
end

up_v = []
row_v = [0]*(C+1)
R.downto(1).each do |r|
    up_v,row_v = row_v,up_v

    v_ary = []
    right_v = 0
    row = rows[r]
    C.downto(1).each do |c|
        v = row[c]

        up = up_v[c]
        right = row_v[c+1] || 0

        if up >= right then
            v_ary = v ? [v] : []
            curr_v = up + (v||0)
        else
            if v then
                v_ary << v
                right += v
                right -= v_ary.sort!.shift if v_ary.count > 3
            end
            curr_v = right
        end

        row_v[c] = curr_v
    end
end

p row_v[1]