import Control.Monad
import Control.Applicative
import Data.List
import qualified Data.Vector.Unboxed as Vec
import Debug.Trace as De

getIntList = map read . words <$> getLine


listToTriple abc =(a,b,c)
    where [a,b,c]=abc
main :: IO ()

fir (a,_,_)=a
sec (_,b,_)=b
trd (_,_,c)=c
main = do
    [r,c,k] <- getIntList
    
    rcv <- map (map read . words) <$> replicateM k getLine
    let uuu=sort(rcv++[[(r+4),(c+4),0]])

    
    let aaa=tail(toHyo r c 1 1 uuu [[]])
    let mat= map reverse (reverse aaa)
    
    let ans = foldl' (solve [0,0,0,0])    (replicate c [0,0,0,0])    mat
    putStrLn (show ((last ans)!!3))

toHyo :: Int->Int->Int->Int->[[Int]]->[[Int]] -> [[Int]]
toHyo r c y x rcv now
    | r<y = now
    | c<x = toHyo r c (y+1) 1 rcv    ([[]]++now )
    | y==sy && x==sx = toHyo r c y (x+1) (tail rcv) ((sv:(head now)):(tail now)) 
    | otherwise = toHyo r c y (x+1) rcv ((0:(head now)):(tail now)) 
        where
            [sy,sx,sv]=head rcv



solve::    [Int]-> [[Int]] -> [Int] -> [[Int]]
solve hd ue vs 
    | ue==[]    = []
    | otherwise = it:(solve it (tail ue) (tail vs))
        where 
            
            hdue= (map (max (last(head ue))) hd)
            it :: [Int]
            it = (dp hdue (head vs) (-1000000000))

dp:: [Int] -> Int -> Int -> [Int]
dp hdue v mae
    | hdue==[] = []
    | otherwise = (max (mae+v) (head hdue)):dp (tail hdue) v (head hdue)
            
            

