import bisect
import sys,io
import math
from collections import deque
from heapq import heappush, heappop

input = sys.stdin.buffer.readline

def sRaw():
    return input().rstrip("\r")


def iRaw():
    return int(input())


def ssRaw():
    return input().split()


def isRaw():
    return list(map(int, ssRaw()))

INF = 1 << 29

DIV = (10**9) + 7
#DIV = 998244353

def mod_inv_prime(a, mod=DIV):
    return pow(a, mod-2, mod)


def mod_inv(a, b):
    r = a
    w = b
    u = 1
    v = 0
    while w != 0:
        t = r//w
        r -= t*w
        r, w = w, r
        u -= t*v
        u, v = v, u
    return (u % b+b) % b


def CONV_TBL(max, mod=DIV):
    fac, finv, inv = [0]*max, [0]*max, [0]*max
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1
    for i in range(2, max):
        fac[i] = fac[i-1]*i % mod
        inv[i] = mod - inv[mod % i] * (mod//i) % mod
        finv[i] = finv[i-1]*inv[i] % mod

    class CONV:
        def __init__(self):
            self.fac = fac
            self.finv = finv
            pass

        def ncr(self, n, k):
            if(n < k):
                return 0
            if(n < 0 or k < 0):
                return 0
            return fac[n]*(finv[k]*finv[n-k] % DIV) % DIV

    return CONV()


def cumsum(As):
    s = 0
    for a in As:
        s += a
        yield s


sys.setrecursionlimit(200005)


def dijkstra(G,start=0):
    heap = []
    cost = [INF]*len(G)
    heappush(heap,(0,start))
    while len(heap)!=0:
        c,n = heappop(heap)
        if cost[n] !=INF:
            continue
        cost[n]=c
        for e in G[n]:
            ec,v = e
            if cost[v]!=INF:
                continue
            heappush(heap,(ec+c,v))
    return cost


def main():
    R,C,K = isRaw()
    mas = [[0 for _ in range(C)]for _ in range(R)]
    for k in range(K):
        r,c,v = isRaw()
        mas[r-1][c-1]=v
    dp = [[[0 for _ in range(C)] for _ in range(R)] for _ in range(3)]

    dp0 = dp[0]
    dp1 = dp[1]
    dp2 = dp[2]

    dp0[0][0]=mas[0][0]
    dp1[0][0]=mas[0][0]
    dp2[0][0]=mas[0][0]

    for r in range(R):
        for c in range(C):
            mrc = mas[r][c]
            
            dp0[r][c] = mrc
            dp1[r][c] = mrc
            dp2[r][c] = mrc

            if r>0:
                dp0[r][c] = max(dp0[r][c], dp2[r-1][c]+mrc)
                dp1[r][c] = max(dp1[r][c], dp2[r-1][c]+mrc)
                dp2[r][c] = max(dp2[r][c], dp2[r-1][c]+mrc)
            if c>0:
                dp0[r][c] = max(dp0[r][c], dp0[r][c-1], mrc)
                dp1[r][c] = max(dp1[r][c], dp1[r][c-1], dp0[r][c-1]+mrc)
                dp2[r][c] = max(dp2[r][c], dp2[r][c-1], dp1[r][c-1]+mrc)

    print(max([dp[ni][-1][-1] for ni in range(3)]))

main() import bisect bisect import sys,io sys io import math math from collections import deque from heapq import heappush, heappop input = sys.stdin.buffer.readline input sys.stdin.buffer.readline sys.stdin.buffer sys.stdin sys stdin buffer readline def sRaw():
    return input().rstrip("\r") sRaw return input().rstrip("\r") input().rstrip("\r") ().rstrip () input rstrip "\r" def iRaw():
    return int(input()) iRaw return int(input()) int(input()) int input() input def ssRaw():
    return input().split() ssRaw return input().split() input().split() ().split () input split def isRaw():
    return list(map(int, ssRaw())) isRaw return list(map(int, ssRaw())) list(map(int, ssRaw())) list map(int, ssRaw()) map int ssRaw() ssRaw INF = 1 << 29 INF 1 << 29 1 29 DIV = (10**9) + 7 DIV (10**9) + 7 10**9 10 9 7 def mod_inv_prime(a, mod=DIV):
    return pow(a, mod-2, mod) mod_inv_prime return pow(a, mod-2, mod) pow(a, mod-2, mod) pow a mod-2 mod 2 mod a a mod=DIV mod DIV def mod_inv(a, b):
    r = a
    w = b
    u = 1
    v = 0
    while w != 0:
        t = r//w
        r -= t*w
        r, w = w, r
        u -= t*v
        u, v = v, u
    return (u % b+b) % b mod_inv r = a r a w = b w b u = 1 u 1 v = 0 v 0 while w != 0:
        t = r//w
        r -= t*w
        r, w = w, r
        u -= t*v
        u, v = v, u
     w != 0 w 0 t = r//w t r//w r w r -= t*w r t*w t w r, w = w, r r w w r u -= t*v u t*v t v u, v = v, u u v v u return (u % b+b) % b (u % b+b) % b u % b+b u % b u b b b a a b b def CONV_TBL(max, mod=DIV):
    fac, finv, inv = [0]*max, [0]*max, [0]*max
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1
    for i in range(2, max):
        fac[i] = fac[i-1]*i % mod
        inv[i] = mod - inv[mod % i] * (mod//i) % mod
        finv[i] = finv[i-1]*inv[i] % mod

    class CONV:
        def __init__(self):
            self.fac = fac
            self.finv = finv
            pass

        def ncr(self, n, k):
            if(n < k):
                return 0
            if(n < 0 or k < 0):
                return 0
            return fac[n]*(finv[k]*finv[n-k] % DIV) % DIV

    return CONV() CONV_TBL fac, finv, inv = [0]*max, [0]*max, [0]*max fac [0]*max [0] 0 max finv [0]*max [0] 0 max inv [0]*max [0] 0 max fac[0] = fac[1] = 1 fac[0] fac 0 1 = fac[1] = 1 fac[1] fac 1 1 finv[0] = finv[1] = 1 finv[0] finv 0 1 = finv[1] = 1 finv[1] finv 1 1 inv[1] = 1 inv[1] inv 1 1 for i in range(2, max):
        fac[i] = fac[i-1]*i % mod
        inv[i] = mod - inv[mod % i] * (mod//i) % mod
        finv[i] = finv[i-1]*inv[i] % mod

     i range(2, max) range 2 max fac[i] = fac[i-1]*i % mod fac[i] fac i fac[i-1]*i % mod fac[i-1]*i fac[i-1] fac i-1 i 1 i mod inv[i] = mod - inv[mod % i] * (mod//i) % mod inv[i] inv i mod - inv[mod % i] * (mod//i) % mod mod inv[mod % i] * (mod//i) % mod inv[mod % i] * (mod//i) inv[mod % i] inv mod % i mod i mod//i mod i mod finv[i] = finv[i-1]*inv[i] % mod finv[i] finv i finv[i-1]*inv[i] % mod finv[i-1]*inv[i] finv[i-1] finv i-1 i 1 inv[i] inv i mod class CONV:
        def __init__(self):
            self.fac = fac
            self.finv = finv
            pass

        def ncr(self, n, k):
            if(n < k):
                return 0
            if(n < 0 or k < 0):
                return 0
            return fac[n]*(finv[k]*finv[n-k] % DIV) % DIV

     CONV def __init__(self):
            self.fac = fac
            self.finv = finv
            pass

         __init__ self.fac = fac self.fac self fac fac self.finv = finv self.finv self finv finv self self def ncr(self, n, k):
            if(n < k):
                return 0
            if(n < 0 or k < 0):
                return 0
            return fac[n]*(finv[k]*finv[n-k] % DIV) % DIV

     ncr if(n < k):
                return 0
             n < k n k return 0 0 if(n < 0 or k < 0):
                return 0
             n < 0 or k < 0 n < 0 n 0 k < 0 k 0 return 0 0 return fac[n]*(finv[k]*finv[n-k] % DIV) % DIV fac[n]*(finv[k]*finv[n-k] % DIV) % DIV fac[n]*(finv[k]*finv[n-k] % DIV) fac[n] fac n finv[k]*finv[n-k] % DIV finv[k]*finv[n-k] finv[k] finv k finv[n-k] finv n-k n k DIV DIV self self n n k k return CONV() CONV() CONV max max mod=DIV mod DIV def cumsum(As):
    s = 0
    for a in As:
        s += a
        yield s cumsum s = 0 s 0 for a in As:
        s += a
        yield s a As s += a s a yield s s As As sys.setrecursionlimit(200005) sys.setrecursionlimit sys setrecursionlimit 200005 def dijkstra(G,start=0):
    heap = []
    cost = [INF]*len(G)
    heappush(heap,(0,start))
    while len(heap)!=0:
        c,n = heappop(heap)
        if cost[n] !=INF:
            continue
        cost[n]=c
        for e in G[n]:
            ec,v = e
            if cost[v]!=INF:
                continue
            heappush(heap,(ec+c,v))
    return cost dijkstra heap = [] heap [] cost = [INF]*len(G) cost [INF]*len(G) [INF] INF len(G) len G heappush(heap,(0,start)) heappush heap (0,start) 0 start while len(heap)!=0:
        c,n = heappop(heap)
        if cost[n] !=INF:
            continue
        cost[n]=c
        for e in G[n]:
            ec,v = e
            if cost[v]!=INF:
                continue
            heappush(heap,(ec+c,v))
     len(heap)!=0 len(heap) len heap 0 c,n = heappop(heap) c heappop(heap) heappop heap n if cost[n] !=INF:
            continue
         cost[n] !=INF cost[n] cost n INF continue cost[n]=c cost[n] cost n c for e in G[n]:
            ec,v = e
            if cost[v]!=INF:
                continue
            heappush(heap,(ec+c,v))
     e G[n] G n ec,v = e ec e v if cost[v]!=INF:
                continue
             cost[v]!=INF cost[v] cost v INF continue heappush(heap,(ec+c,v)) heappush heap (ec+c,v) ec+c ec c v return cost cost G G start=0 start 0 def main():
    R,C,K = isRaw()
    mas = [[0 for _ in range(C)]for _ in range(R)]
    for k in range(K):
        r,c,v = isRaw()
        mas[r-1][c-1]=v
    dp = [[[0 for _ in range(C)] for _ in range(R)] for _ in range(3)]

    dp0 = dp[0]
    dp1 = dp[1]
    dp2 = dp[2]

    dp0[0][0]=mas[0][0]
    dp1[0][0]=mas[0][0]
    dp2[0][0]=mas[0][0]

    for r in range(R):
        for c in range(C):
            mrc = mas[r][c]
            
            dp0[r][c] = mrc
            dp1[r][c] = mrc
            dp2[r][c] = mrc

            if r>0:
                dp0[r][c] = max(dp0[r][c], dp2[r-1][c]+mrc)
                dp1[r][c] = max(dp1[r][c], dp2[r-1][c]+mrc)
                dp2[r][c] = max(dp2[r][c], dp2[r-1][c]+mrc)
            if c>0:
                dp0[r][c] = max(dp0[r][c], dp0[r][c-1], mrc)
                dp1[r][c] = max(dp1[r][c], dp1[r][c-1], dp0[r][c-1]+mrc)
                dp2[r][c] = max(dp2[r][c], dp2[r][c-1], dp1[r][c-1]+mrc)

    print(max([dp[ni][-1][-1] for ni in range(3)])) main R,C,K = isRaw() R isRaw() isRaw C K [0 for _ in range(C)]for _ in range(R) for _ in range(R) _ range(R) range R for _ in range(R) [0 for _ in range(C)] mas = [[0 for _ in range(C)]for _ in range(R)] mas [[0 for _ in range(C)]for _ in range(R)] for k in range(K):
        r,c,v = isRaw()
        mas[r-1][c-1]=v
     k range(K) range K r,c,v = isRaw() r isRaw() isRaw c v mas[r-1][c-1]=v mas[r-1][c-1] [r-1] mas r-1 r 1 c-1 c 1 v [[0 for _ in range(C)] for _ in range(R)] for _ in range(3) for _ in range(3) _ range(3) range 3 for _ in range(3) [[0 for _ in range(C)] for _ in range(R)] dp = [[[0 for _ in range(C)] for _ in range(R)] for _ in range(3)] dp [[[0 for _ in range(C)] for _ in range(R)] for _ in range(3)] dp0 = dp[0] dp0 dp[0] dp 0 dp1 = dp[1] dp1 dp[1] dp 1 dp2 = dp[2] dp2 dp[2] dp 2 dp0[0][0]=mas[0][0] dp0[0][0] [0] dp0 0 0 mas[0][0] [0] mas 0 0 dp1[0][0]=mas[0][0] dp1[0][0] [0] dp1 0 0 mas[0][0] [0] mas 0 0 dp2[0][0]=mas[0][0] dp2[0][0] [0] dp2 0 0 mas[0][0] [0] mas 0 0 for r in range(R):
        for c in range(C):
            mrc = mas[r][c]
            
            dp0[r][c] = mrc
            dp1[r][c] = mrc
            dp2[r][c] = mrc

            if r>0:
                dp0[r][c] = max(dp0[r][c], dp2[r-1][c]+mrc)
                dp1[r][c] = max(dp1[r][c], dp2[r-1][c]+mrc)
                dp2[r][c] = max(dp2[r][c], dp2[r-1][c]+mrc)
            if c>0:
                dp0[r][c] = max(dp0[r][c], dp0[r][c-1], mrc)
                dp1[r][c] = max(dp1[r][c], dp1[r][c-1], dp0[r][c-1]+mrc)
                dp2[r][c] = max(dp2[r][c], dp2[r][c-1], dp1[r][c-1]+mrc)

     r range(R) range R for c in range(C):
            mrc = mas[r][c]
            
            dp0[r][c] = mrc
            dp1[r][c] = mrc
            dp2[r][c] = mrc

            if r>0:
                dp0[r][c] = max(dp0[r][c], dp2[r-1][c]+mrc)
                dp1[r][c] = max(dp1[r][c], dp2[r-1][c]+mrc)
                dp2[r][c] = max(dp2[r][c], dp2[r-1][c]+mrc)
            if c>0:
                dp0[r][c] = max(dp0[r][c], dp0[r][c-1], mrc)
                dp1[r][c] = max(dp1[r][c], dp1[r][c-1], dp0[r][c-1]+mrc)
                dp2[r][c] = max(dp2[r][c], dp2[r][c-1], dp1[r][c-1]+mrc)

     c range(C) range C mrc = mas[r][c] mrc mas[r][c] [r] mas r c dp0[r][c] = mrc dp0[r][c] [r] dp0 r c mrc dp1[r][c] = mrc dp1[r][c] [r] dp1 r c mrc dp2[r][c] = mrc dp2[r][c] [r] dp2 r c mrc if r>0:
                dp0[r][c] = max(dp0[r][c], dp2[r-1][c]+mrc)
                dp1[r][c] = max(dp1[r][c], dp2[r-1][c]+mrc)
                dp2[r][c] = max(dp2[r][c], dp2[r-1][c]+mrc)
             r>0 r 0 dp0[r][c] = max(dp0[r][c], dp2[r-1][c]+mrc) dp0[r][c] [r] dp0 r c max(dp0[r][c], dp2[r-1][c]+mrc) max dp0[r][c] [r] dp0 r c dp2[r-1][c]+mrc dp2[r-1][c] [r-1] dp2 r-1 r 1 c mrc dp1[r][c] = max(dp1[r][c], dp2[r-1][c]+mrc) dp1[r][c] [r] dp1 r c max(dp1[r][c], dp2[r-1][c]+mrc) max dp1[r][c] [r] dp1 r c dp2[r-1][c]+mrc dp2[r-1][c] [r-1] dp2 r-1 r 1 c mrc dp2[r][c] = max(dp2[r][c], dp2[r-1][c]+mrc) dp2[r][c] [r] dp2 r c max(dp2[r][c], dp2[r-1][c]+mrc) max dp2[r][c] [r] dp2 r c dp2[r-1][c]+mrc dp2[r-1][c] [r-1] dp2 r-1 r 1 c mrc if c>0:
                dp0[r][c] = max(dp0[r][c], dp0[r][c-1], mrc)
                dp1[r][c] = max(dp1[r][c], dp1[r][c-1], dp0[r][c-1]+mrc)
                dp2[r][c] = max(dp2[r][c], dp2[r][c-1], dp1[r][c-1]+mrc)

     c>0 c 0 dp0[r][c] = max(dp0[r][c], dp0[r][c-1], mrc) dp0[r][c] [r] dp0 r c max(dp0[r][c], dp0[r][c-1], mrc) max dp0[r][c] [r] dp0 r c dp0[r][c-1] [r] dp0 r c-1 c 1 mrc dp1[r][c] = max(dp1[r][c], dp1[r][c-1], dp0[r][c-1]+mrc) dp1[r][c] [r] dp1 r c max(dp1[r][c], dp1[r][c-1], dp0[r][c-1]+mrc) max dp1[r][c] [r] dp1 r c dp1[r][c-1] [r] dp1 r c-1 c 1 dp0[r][c-1]+mrc dp0[r][c-1] [r] dp0 r c-1 c 1 mrc dp2[r][c] = max(dp2[r][c], dp2[r][c-1], dp1[r][c-1]+mrc) dp2[r][c] [r] dp2 r c max(dp2[r][c], dp2[r][c-1], dp1[r][c-1]+mrc) max dp2[r][c] [r] dp2 r c dp2[r][c-1] [r] dp2 r c-1 c 1 dp1[r][c-1]+mrc dp1[r][c-1] [r] dp1 r c-1 c 1 mrc dp[ni][-1][-1] for ni in range(3) for ni in range(3) ni range(3) range 3 for ni in range(3) dp[ni][-1][-1] [-1] [ni] dp ni -1 -1 print(max([dp[ni][-1][-1] for ni in range(3)])) print max([dp[ni][-1][-1] for ni in range(3)]) max [dp[ni][-1][-1] for ni in range(3)] main() main def mod_inv(a, b):
    r = a
    w = b
    u = 1
    v = 0
    while w != 0:
        t = r//w
        r -= t*w
        r, w = w, r
        u -= t*v
        u, v = v, u
    return (u % b+b) % b def mod_inv(a, b):
    r = a
    w = b
    u = 1
    v = 0
    while w != 0:
        t = r//w
        r -= t*w
        r, w = w, r
        u -= t*v
        u, v = v, u
    return (u % b+b) % b mod_inv input = sys.stdin.buffer.readline sys.stdin.buffer.readline input def isRaw():
    return list(map(int, ssRaw())) def isRaw():
    return list(map(int, ssRaw())) isRaw def cumsum(As):
    s = 0
    for a in As:
        s += a
        yield s def cumsum(As):
    s = 0
    for a in As:
        s += a
        yield s cumsum def iRaw():
    return int(input()) def iRaw():
    return int(input()) iRaw INF = 1 << 29 1 << 29 INF def dijkstra(G,start=0):
    heap = []
    cost = [INF]*len(G)
    heappush(heap,(0,start))
    while len(heap)!=0:
        c,n = heappop(heap)
        if cost[n] !=INF:
            continue
        cost[n]=c
        for e in G[n]:
            ec,v = e
            if cost[v]!=INF:
                continue
            heappush(heap,(ec+c,v))
    return cost def dijkstra(G,start=0):
    heap = []
    cost = [INF]*len(G)
    heappush(heap,(0,start))
    while len(heap)!=0:
        c,n = heappop(heap)
        if cost[n] !=INF:
            continue
        cost[n]=c
        for e in G[n]:
            ec,v = e
            if cost[v]!=INF:
                continue
            heappush(heap,(ec+c,v))
    return cost dijkstra def mod_inv_prime(a, mod=DIV):
    return pow(a, mod-2, mod) def mod_inv_prime(a, mod=DIV):
    return pow(a, mod-2, mod) mod_inv_prime def main():
    R,C,K = isRaw()
    mas = [[0 for _ in range(C)]for _ in range(R)]
    for k in range(K):
        r,c,v = isRaw()
        mas[r-1][c-1]=v
    dp = [[[0 for _ in range(C)] for _ in range(R)] for _ in range(3)]

    dp0 = dp[0]
    dp1 = dp[1]
    dp2 = dp[2]

    dp0[0][0]=mas[0][0]
    dp1[0][0]=mas[0][0]
    dp2[0][0]=mas[0][0]

    for r in range(R):
        for c in range(C):
            mrc = mas[r][c]
            
            dp0[r][c] = mrc
            dp1[r][c] = mrc
            dp2[r][c] = mrc

            if r>0:
                dp0[r][c] = max(dp0[r][c], dp2[r-1][c]+mrc)
                dp1[r][c] = max(dp1[r][c], dp2[r-1][c]+mrc)
                dp2[r][c] = max(dp2[r][c], dp2[r-1][c]+mrc)
            if c>0:
                dp0[r][c] = max(dp0[r][c], dp0[r][c-1], mrc)
                dp1[r][c] = max(dp1[r][c], dp1[r][c-1], dp0[r][c-1]+mrc)
                dp2[r][c] = max(dp2[r][c], dp2[r][c-1], dp1[r][c-1]+mrc)

    print(max([dp[ni][-1][-1] for ni in range(3)])) def main():
    R,C,K = isRaw()
    mas = [[0 for _ in range(C)]for _ in range(R)]
    for k in range(K):
        r,c,v = isRaw()
        mas[r-1][c-1]=v
    dp = [[[0 for _ in range(C)] for _ in range(R)] for _ in range(3)]

    dp0 = dp[0]
    dp1 = dp[1]
    dp2 = dp[2]

    dp0[0][0]=mas[0][0]
    dp1[0][0]=mas[0][0]
    dp2[0][0]=mas[0][0]

    for r in range(R):
        for c in range(C):
            mrc = mas[r][c]
            
            dp0[r][c] = mrc
            dp1[r][c] = mrc
            dp2[r][c] = mrc

            if r>0:
                dp0[r][c] = max(dp0[r][c], dp2[r-1][c]+mrc)
                dp1[r][c] = max(dp1[r][c], dp2[r-1][c]+mrc)
                dp2[r][c] = max(dp2[r][c], dp2[r-1][c]+mrc)
            if c>0:
                dp0[r][c] = max(dp0[r][c], dp0[r][c-1], mrc)
                dp1[r][c] = max(dp1[r][c], dp1[r][c-1], dp0[r][c-1]+mrc)
                dp2[r][c] = max(dp2[r][c], dp2[r][c-1], dp1[r][c-1]+mrc)

    print(max([dp[ni][-1][-1] for ni in range(3)])) main DIV = (10**9) + 7 (10**9) + 7 DIV def sRaw():
    return input().rstrip("\r") def sRaw():
    return input().rstrip("\r") sRaw def ssRaw():
    return input().split() def ssRaw():
    return input().split() ssRaw def CONV_TBL(max, mod=DIV):
    fac, finv, inv = [0]*max, [0]*max, [0]*max
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1
    for i in range(2, max):
        fac[i] = fac[i-1]*i % mod
        inv[i] = mod - inv[mod % i] * (mod//i) % mod
        finv[i] = finv[i-1]*inv[i] % mod

    class CONV:
        def __init__(self):
            self.fac = fac
            self.finv = finv
            pass

        def ncr(self, n, k):
            if(n < k):
                return 0
            if(n < 0 or k < 0):
                return 0
            return fac[n]*(finv[k]*finv[n-k] % DIV) % DIV

    return CONV() def CONV_TBL(max, mod=DIV):
    fac, finv, inv = [0]*max, [0]*max, [0]*max
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1
    for i in range(2, max):
        fac[i] = fac[i-1]*i % mod
        inv[i] = mod - inv[mod % i] * (mod//i) % mod
        finv[i] = finv[i-1]*inv[i] % mod

    class CONV:
        def __init__(self):
            self.fac = fac
            self.finv = finv
            pass

        def ncr(self, n, k):
            if(n < k):
                return 0
            if(n < 0 or k < 0):
                return 0
            return fac[n]*(finv[k]*finv[n-k] % DIV) % DIV

    return CONV() CONV_TBL
import bisect
import sys,io
import math
from collections import deque
from heapq import heappush, heappop

input = sys.stdin.buffer.readline

def sRaw():
    return input().rstrip("\r")


def iRaw():
    return int(input())


def ssRaw():
    return input().split()


def isRaw():
    return list(map(int, ssRaw()))

INF = 1 << 29

DIV = (10**9) + 7
#DIV = 998244353

def mod_inv_prime(a, mod=DIV):
    return pow(a, mod-2, mod)


def mod_inv(a, b):
    r = a
    w = b
    u = 1
    v = 0
    while w != 0:
        t = r//w
        r -= t*w
        r, w = w, r
        u -= t*v
        u, v = v, u
    return (u % b+b) % b


def CONV_TBL(max, mod=DIV):
    fac, finv, inv = [0]*max, [0]*max, [0]*max
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1
    for i in range(2, max):
        fac[i] = fac[i-1]*i % mod
        inv[i] = mod - inv[mod % i] * (mod//i) % mod
        finv[i] = finv[i-1]*inv[i] % mod

    class CONV:
        def __init__(self):
            self.fac = fac
            self.finv = finv
            pass

        def ncr(self, n, k):
            if(n < k):
                return 0
            if(n < 0 or k < 0):
                return 0
            return fac[n]*(finv[k]*finv[n-k] % DIV) % DIV

    return CONV()


def cumsum(As):
    s = 0
    for a in As:
        s += a
        yield s


sys.setrecursionlimit(200005)


def dijkstra(G,start=0):
    heap = []
    cost = [INF]*len(G)
    heappush(heap,(0,start))
    while len(heap)!=0:
        c,n = heappop(heap)
        if cost[n] !=INF:
            continue
        cost[n]=c
        for e in G[n]:
            ec,v = e
            if cost[v]!=INF:
                continue
            heappush(heap,(ec+c,v))
    return cost


def main():
    R,C,K = isRaw()
    mas = [[0 for _ in range(C)]for _ in range(R)]
    for k in range(K):
        r,c,v = isRaw()
        mas[r-1][c-1]=v
    dp = [[[0 for _ in range(C)] for _ in range(R)] for _ in range(3)]

    dp0 = dp[0]
    dp1 = dp[1]
    dp2 = dp[2]

    dp0[0][0]=mas[0][0]
    dp1[0][0]=mas[0][0]
    dp2[0][0]=mas[0][0]

    for r in range(R):
        for c in range(C):
            mrc = mas[r][c]
            
            dp0[r][c] = mrc
            dp1[r][c] = mrc
            dp2[r][c] = mrc

            if r>0:
                dp0[r][c] = max(dp0[r][c], dp2[r-1][c]+mrc)
                dp1[r][c] = max(dp1[r][c], dp2[r-1][c]+mrc)
                dp2[r][c] = max(dp2[r][c], dp2[r-1][c]+mrc)
            if c>0:
                dp0[r][c] = max(dp0[r][c], dp0[r][c-1], mrc)
                dp1[r][c] = max(dp1[r][c], dp1[r][c-1], dp0[r][c-1]+mrc)
                dp2[r][c] = max(dp2[r][c], dp2[r][c-1], dp1[r][c-1]+mrc)

    print(max([dp[ni][-1][-1] for ni in range(3)]))

main()
