import java.util.*
import kotlin.math.absoluteValue
import kotlin.math.max

data class Item(val row: Int, val column: Int, val value: Int)
fun main() {
    val (row, column, k) = readLine()!!.trim().split(' ').map(String::toInt)
    val items = Array(k) {
        val (r, c, v) = readLine()!!.trim().split(' ').map(String::toInt)
        Item(r, c, v)
    }.groupBy { it.row }
    val memo = Array(2){LongArray(column + 1){0L} }
    for (r in 1 .. row) {
        val current = memo[r and 1]
        val prev = memo[(r and 1) xor 1]
        val maxScore = LongArray(4){0L}
        val item = items[r]?.associateBy(Item::column) ?: mapOf()
        for (c in 1 .. column) {
            maxScore[0] = max(maxScore[0], prev[c])
            when(val i = item[c]) {
                null -> Unit
                else -> {
                    for (j in 1 .. 3) {
                        maxScore[4 - j] = max(maxScore[4 - j], maxScore[3 - j] + i.value)
                    }
                }
            }
            current[c] = maxScore.max()!!
        }
    }
    println(memo[row and 1].last())
}