import sys
from collections import deque
import bisect
import copy
import heapq
import itertools
import math
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
mod = 10 ** 9 + 7

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]


class V:
    def __init__(self, f, v=None):
        self.f = f
        self.v = v
 
    def __str__(self):
        return str(self.v)
 
    def ud(self, n):
        if n is None:
            return

        if self.v is None:
            self.v = n
            return
        self.v = self.f(self.v, n) 


def main():
    R, C, K = read_values()
    V = [0] * (R * C)
    for _ in range(K):
        r, c, v = read_values()
        r -= 1
        c -= 1
        V[r * C + c] = v
    
    dp = [[0] * (R * C) for _ in range(4)]
    for i in range(R * C):
        r = i // C
        c = i % C
        if c + 1 < C:
            # not take
            for k in range(4):
                dp[k][i + 1]= max(dp[k][i + 1], dp[k][i])

            # take 
            for k in range(3):
                dp[k + 1][i + 1] = max(dp[k + 1][i + 1], dp[k][i] + V[i])

        # next r
        if r + 1 < R:
            for k in range(4):
                dp[0][i + C] = max(dp[0][i + C], dp[k][i] + (V[i] if k < 3 else 0))

    res = 0
    for k in range(4):
        res = max(res, dp[k][-1] + (V[-1] if k < 3 else 0))
    print(res)


if __name__ == "__main__":
    main()
 import sys sys from collections import deque import bisect bisect import copy copy import heapq heapq import itertools itertools import math math input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline sys.setrecursionlimit(1000000) sys.setrecursionlimit sys setrecursionlimit 1000000 mod = 10 ** 9 + 7 mod 10 ** 9 + 7 10 ** 9 10 9 7 def read_values(): return map(int, input().split()) read_values def read_index(): return map(lambda x: int(x) - 1, input().split()) read_index def read_list(): return list(read_values()) read_list read_list() for n in range(N) for n in range(N) n range(N) range N for n in range(N) read_list() read_list def read_lists(N): return [read_list() for n in range(N)] read_lists N N class V:
    def __init__(self, f, v=None):
        self.f = f
        self.v = v
 
    def __str__(self):
        return str(self.v)
 
    def ud(self, n):
        if n is None:
            return

        if self.v is None:
            self.v = n
            return
        self.v = self.f(self.v, n)  V def __init__(self, f, v=None):
        self.f = f
        self.v = v
 
     __init__ self.f = f self.f self f f self.v = v self.v self v v self self f f v=None v None def __str__(self):
        return str(self.v)
 
     __str__ return str(self.v) str(self.v) str self.v self v self self def ud(self, n):
        if n is None:
            return

        if self.v is None:
            self.v = n
            return
        self.v = self.f(self.v, n)  ud if n is None:
            return

         n is None n None return if self.v is None:
            self.v = n
            return
         self.v is None self.v self v None self.v = n self.v self v n return self.v = self.f(self.v, n) self.v self v self.f(self.v, n) self.f self f self.v self v n self self n n def main():
    R, C, K = read_values()
    V = [0] * (R * C)
    for _ in range(K):
        r, c, v = read_values()
        r -= 1
        c -= 1
        V[r * C + c] = v
    
    dp = [[0] * (R * C) for _ in range(4)]
    for i in range(R * C):
        r = i // C
        c = i % C
        if c + 1 < C:
            # not take
            for k in range(4):
                dp[k][i + 1]= max(dp[k][i + 1], dp[k][i])

            # take 
            for k in range(3):
                dp[k + 1][i + 1] = max(dp[k + 1][i + 1], dp[k][i] + V[i])

        # next r
        if r + 1 < R:
            for k in range(4):
                dp[0][i + C] = max(dp[0][i + C], dp[k][i] + (V[i] if k < 3 else 0))

    res = 0
    for k in range(4):
        res = max(res, dp[k][-1] + (V[-1] if k < 3 else 0))
    print(res) main R, C, K = read_values() R read_values() read_values C K V = [0] * (R * C) V [0] * (R * C) [0] 0 R * C R C for _ in range(K):
        r, c, v = read_values()
        r -= 1
        c -= 1
        V[r * C + c] = v
    
     _ range(K) range K r, c, v = read_values() r read_values() read_values c v r -= 1 r 1 c -= 1 c 1 V[r * C + c] = v V[r * C + c] V r * C + c r * C r C c v [0] * (R * C) for _ in range(4) for _ in range(4) _ range(4) range 4 for _ in range(4) [0] * (R * C) [0] 0 R * C R C dp = [[0] * (R * C) for _ in range(4)] dp [[0] * (R * C) for _ in range(4)] for i in range(R * C):
        r = i // C
        c = i % C
        if c + 1 < C:
            # not take
            for k in range(4):
                dp[k][i + 1]= max(dp[k][i + 1], dp[k][i])

            # take 
            for k in range(3):
                dp[k + 1][i + 1] = max(dp[k + 1][i + 1], dp[k][i] + V[i])

        # next r
        if r + 1 < R:
            for k in range(4):
                dp[0][i + C] = max(dp[0][i + C], dp[k][i] + (V[i] if k < 3 else 0))

     i range(R * C) range R * C R C r = i // C r i // C i C c = i % C c i % C i C if c + 1 < C:
            # not take
            for k in range(4):
                dp[k][i + 1]= max(dp[k][i + 1], dp[k][i])

            # take 
            for k in range(3):
                dp[k + 1][i + 1] = max(dp[k + 1][i + 1], dp[k][i] + V[i])

        # next r
         c + 1 < C c + 1 c 1 C for k in range(4):
                dp[k][i + 1]= max(dp[k][i + 1], dp[k][i])

            # take 
             k range(4) range 4 dp[k][i + 1]= max(dp[k][i + 1], dp[k][i]) dp[k][i + 1] [k] dp k i + 1 i 1 max(dp[k][i + 1], dp[k][i]) max dp[k][i + 1] [k] dp k i + 1 i 1 dp[k][i] [k] dp k i for k in range(3):
                dp[k + 1][i + 1] = max(dp[k + 1][i + 1], dp[k][i] + V[i])

        # next r
         k range(3) range 3 dp[k + 1][i + 1] = max(dp[k + 1][i + 1], dp[k][i] + V[i]) dp[k + 1][i + 1] [k + 1] dp k + 1 k 1 i + 1 i 1 max(dp[k + 1][i + 1], dp[k][i] + V[i]) max dp[k + 1][i + 1] [k + 1] dp k + 1 k 1 i + 1 i 1 dp[k][i] + V[i] dp[k][i] [k] dp k i V[i] V i if r + 1 < R:
            for k in range(4):
                dp[0][i + C] = max(dp[0][i + C], dp[k][i] + (V[i] if k < 3 else 0))

     r + 1 < R r + 1 r 1 R for k in range(4):
                dp[0][i + C] = max(dp[0][i + C], dp[k][i] + (V[i] if k < 3 else 0))

     k range(4) range 4 dp[0][i + C] = max(dp[0][i + C], dp[k][i] + (V[i] if k < 3 else 0)) dp[0][i + C] [0] dp 0 i + C i C max(dp[0][i + C], dp[k][i] + (V[i] if k < 3 else 0)) max dp[0][i + C] [0] dp 0 i + C i C dp[k][i] + (V[i] if k < 3 else 0) dp[k][i] [k] dp k i V[i] if k < 3 else 0 k < 3 k 3 V[i] V i 0 res = 0 res 0 for k in range(4):
        res = max(res, dp[k][-1] + (V[-1] if k < 3 else 0))
     k range(4) range 4 res = max(res, dp[k][-1] + (V[-1] if k < 3 else 0)) res max(res, dp[k][-1] + (V[-1] if k < 3 else 0)) max res dp[k][-1] + (V[-1] if k < 3 else 0) dp[k][-1] [k] dp k -1 V[-1] if k < 3 else 0 k < 3 k 3 V[-1] V -1 0 print(res) print res if __name__ == "__main__":
    main() __name__ == "__main__" __name__ "__main__" main() main def read_values(): return map(int, input().split()) def read_values(): return map(int, input().split()) read_values class V:
    def __init__(self, f, v=None):
        self.f = f
        self.v = v
 
    def __str__(self):
        return str(self.v)
 
    def ud(self, n):
        if n is None:
            return

        if self.v is None:
            self.v = n
            return
        self.v = self.f(self.v, n)  class V:
    def __init__(self, f, v=None):
        self.f = f
        self.v = v
 
    def __str__(self):
        return str(self.v)
 
    def ud(self, n):
        if n is None:
            return

        if self.v is None:
            self.v = n
            return
        self.v = self.f(self.v, n)  V def read_index(): return map(lambda x: int(x) - 1, input().split()) def read_index(): return map(lambda x: int(x) - 1, input().split()) read_index input = sys.stdin.readline sys.stdin.readline input def read_list(): return list(read_values()) def read_list(): return list(read_values()) read_list def main():
    R, C, K = read_values()
    V = [0] * (R * C)
    for _ in range(K):
        r, c, v = read_values()
        r -= 1
        c -= 1
        V[r * C + c] = v
    
    dp = [[0] * (R * C) for _ in range(4)]
    for i in range(R * C):
        r = i // C
        c = i % C
        if c + 1 < C:
            # not take
            for k in range(4):
                dp[k][i + 1]= max(dp[k][i + 1], dp[k][i])

            # take 
            for k in range(3):
                dp[k + 1][i + 1] = max(dp[k + 1][i + 1], dp[k][i] + V[i])

        # next r
        if r + 1 < R:
            for k in range(4):
                dp[0][i + C] = max(dp[0][i + C], dp[k][i] + (V[i] if k < 3 else 0))

    res = 0
    for k in range(4):
        res = max(res, dp[k][-1] + (V[-1] if k < 3 else 0))
    print(res) def main():
    R, C, K = read_values()
    V = [0] * (R * C)
    for _ in range(K):
        r, c, v = read_values()
        r -= 1
        c -= 1
        V[r * C + c] = v
    
    dp = [[0] * (R * C) for _ in range(4)]
    for i in range(R * C):
        r = i // C
        c = i % C
        if c + 1 < C:
            # not take
            for k in range(4):
                dp[k][i + 1]= max(dp[k][i + 1], dp[k][i])

            # take 
            for k in range(3):
                dp[k + 1][i + 1] = max(dp[k + 1][i + 1], dp[k][i] + V[i])

        # next r
        if r + 1 < R:
            for k in range(4):
                dp[0][i + C] = max(dp[0][i + C], dp[k][i] + (V[i] if k < 3 else 0))

    res = 0
    for k in range(4):
        res = max(res, dp[k][-1] + (V[-1] if k < 3 else 0))
    print(res) main mod = 10 ** 9 + 7 10 ** 9 + 7 mod def read_lists(N): return [read_list() for n in range(N)] def read_lists(N): return [read_list() for n in range(N)] read_lists
import sys
from collections import deque
import bisect
import copy
import heapq
import itertools
import math
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
mod = 10 ** 9 + 7

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]


class V:
    def __init__(self, f, v=None):
        self.f = f
        self.v = v
 
    def __str__(self):
        return str(self.v)
 
    def ud(self, n):
        if n is None:
            return

        if self.v is None:
            self.v = n
            return
        self.v = self.f(self.v, n) 


def main():
    R, C, K = read_values()
    V = [0] * (R * C)
    for _ in range(K):
        r, c, v = read_values()
        r -= 1
        c -= 1
        V[r * C + c] = v
    
    dp = [[0] * (R * C) for _ in range(4)]
    for i in range(R * C):
        r = i // C
        c = i % C
        if c + 1 < C:
            # not take
            for k in range(4):
                dp[k][i + 1]= max(dp[k][i + 1], dp[k][i])

            # take 
            for k in range(3):
                dp[k + 1][i + 1] = max(dp[k + 1][i + 1], dp[k][i] + V[i])

        # next r
        if r + 1 < R:
            for k in range(4):
                dp[0][i + C] = max(dp[0][i + C], dp[k][i] + (V[i] if k < 3 else 0))

    res = 0
    for k in range(4):
        res = max(res, dp[k][-1] + (V[-1] if k < 3 else 0))
    print(res)


if __name__ == "__main__":
    main()

