r, c, k = gets.split.map(&:to_i)

m = Array.new(r+1) {Array.new(c+1, 0)}
k.times do
    a, b, v = gets.split.map(&:to_i)
    m[a][b] = v
end

1.upto(r) do |i|
    x = []
    1.upto(c) do |j|
        if m[i][j] == 0
            if m[i-1][j] >= m[i][j-1]
                x = []
                m[i][j] = m[i-1][j]
            else
                m[i][j] = m[i][j-1]
            end
        elsif x.size != 3
            if m[i-1][j] >= m[i][j-1]
                x = [m[i][j]]
                m[i][j] += m[i-1][j]
            else
                x << m[i][j]
                m[i][j] += m[i][j-1]
            end
        else
            y = x.min
            if y >= m[i][j]
                if m[i-1][j] + m[i][j] >= m[i][j-1]
                    m[i][j] += m[i-1][j]
                    x = []
                else
                    m[i][j] = m[i][j-1]
                end
            else
                if m[i-1][j] >= m[i][j-1] - y
                    x = [m[i][j]]
                    m[i][j] += m[i-1][j]
                else
                    x.delete_at(x.index(y))
                    x << m[i][j]
                    m[i][j] += m[i][j-1] - y
                end
            end
        end
    end
end

p m[r][c]