#if os(Linux)
import Glibc
#else
import Darwin.C
#endif

let INPUT = stdin

var buffer: UnsafeMutablePointer<CChar>?
var bufferCapacity: Int32 = 0

func getsToBuffer(size: Int32) -> UnsafeMutablePointer<CChar> {
    if bufferCapacity < size {
        buffer?.deallocate()
        buffer = UnsafeMutablePointer.allocate(capacity: Int(size))
        bufferCapacity = size
    }
    return fgets(buffer!, size, INPUT)
}
func getIntFromBuffer(_ ptr: inout UnsafeMutablePointer<CChar>) -> Int {
    var minus = false
    var x: Int?
    while true {
        switch ptr.pointee {
        case 0x2D:
            assert(!minus && x == nil)
            minus = true
        case let d where (0x30...0x39).contains(d):
            x = (x ?? 0)*10 + Int(d)-0x30
        default:
            if x != nil { return minus ? -x! : x! }
        }
        ptr += 1
    }
}
func getInt() -> Int {
    var xPtr = getsToBuffer(size: 24)
    return getIntFromBuffer(&xPtr)
}
func getIntPair() -> (Int, Int) {
    var xPtr = getsToBuffer(size: 2*24)
    let x1 = getIntFromBuffer(&xPtr)
    let x2 = getIntFromBuffer(&xPtr)
    return (x1, x2)
}
func getIntTriplet() -> (Int, Int, Int) {
    var xPtr = getsToBuffer(size: 2*24)
    let x1 = getIntFromBuffer(&xPtr)
    let x2 = getIntFromBuffer(&xPtr)
    let x3 = getIntFromBuffer(&xPtr)
    return (x1, x2, x3)
}
func getInts(count: Int) -> [Int] {
    var xPtr = getsToBuffer(size: Int32(count) * 24)
    var a = [Int]()
    a.reserveCapacity(count)
    for _ in 0..<count { a.append(getIntFromBuffer(&xPtr)) }
    return a
}

//=============================================================================

struct Table {
    private var data: [Int]
    private let d1, d2, d3: Int
    private let s1, s2: Int
    init(_ d1: Int, _ d2: Int, _ d3: Int) {
        self.d1 = d1
        self.d2 = d2
        self.d3 = d3
        s1 = d2 * d3
        s2 = d3
        data = [Int](repeating: 0, count: d1*d2*d3)
    }
    subscript(i: Int, j: Int, k: Int) -> Int {
        get { data[i*s1 + j*s2 + k] }
        set { data[i*s1 + j*s2 + k] = newValue }
    }
}

let (R, C, K) = getIntTriplet()
var items = Table(R+1, C+1, 1)
for _ in 0..<K {
    let (r, c, v) = getIntTriplet()
    items[r, c, 0] = v
}

var dp = Table(R+1, C+1, 4)

for i in 1...R {
    for j in 1...C {
        let item = items[i, j, 0]
        let maxUp = max(dp[i-1, j, 0], dp[i-1, j, 1], dp[i-1, j, 2], dp[i-1, j, 3])
        dp[i, j, 0] = maxUp
        dp[i, j, 1] = maxUp + item
        for k in 0...3 { dp[i, j, k] = max(dp[i, j, k], dp[i, j-1, k]) }
        for k in 1...3 { dp[i, j, k] = max(dp[i, j, k], dp[i, j-1, k-1] + item)}
    }
}

print(max(dp[R, C, 0], dp[R, C, 1], dp[R, C, 2], dp[R, C, 3]))
