import sys
input = sys.stdin.readline

R,C,K=list(map(int,input().split()))
itemMap = [[0]*(C+1) for _ in range(R+1)]
dp =[[[0]*(C+1) for _ in range(R+1)] for _ in range(4)]

for _ in range(K):
    r,c,v=list(map(int,input().split()))
    itemMap[r-1][c-1]=v

for ir in range(R):
    for ic in range(C):
        for k in range(2,-1,-1):
            #-拾う拾わない遷移-#
            dp[k+1][ir][ic] = max(dp[k+1][ir][ic],dp[k][ir][ic]+itemMap[ir][ic])
        #-位置遷移-#
        for k in range(4):
            dp[0][ir+1][ic] = max(dp[0][ir+1][ic],dp[k][ir][ic])
            dp[k][ir][ic+1] = max(dp[k][ir][ic+1],dp[k][ir][ic])

ans = 0
for k in range(4):
    ans = max(ans,dp[k][R-1][C-1])
print(ans)
                            
                         import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline R,C,K=list(map(int,input().split())) R list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split C K [0]*(C+1) for _ in range(R+1) for _ in range(R+1) _ range(R+1) range R+1 R 1 for _ in range(R+1) [0]*(C+1) [0] 0 C+1 C 1 itemMap = [[0]*(C+1) for _ in range(R+1)] itemMap [[0]*(C+1) for _ in range(R+1)] [[0]*(C+1) for _ in range(R+1)] for _ in range(4) for _ in range(4) _ range(4) range 4 for _ in range(4) [[0]*(C+1) for _ in range(R+1)] dp =[[[0]*(C+1) for _ in range(R+1)] for _ in range(4)] dp [[[0]*(C+1) for _ in range(R+1)] for _ in range(4)] for _ in range(K):
    r,c,v=list(map(int,input().split()))
    itemMap[r-1][c-1]=v _ range(K) range K r,c,v=list(map(int,input().split())) r list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split c v itemMap[r-1][c-1]=v itemMap[r-1][c-1] [r-1] itemMap r-1 r 1 c-1 c 1 v for ir in range(R):
    for ic in range(C):
        for k in range(2,-1,-1):
            #-拾う拾わない遷移-#
            dp[k+1][ir][ic] = max(dp[k+1][ir][ic],dp[k][ir][ic]+itemMap[ir][ic])
        #-位置遷移-#
        for k in range(4):
            dp[0][ir+1][ic] = max(dp[0][ir+1][ic],dp[k][ir][ic])
            dp[k][ir][ic+1] = max(dp[k][ir][ic+1],dp[k][ir][ic]) ir range(R) range R for ic in range(C):
        for k in range(2,-1,-1):
            #-拾う拾わない遷移-#
            dp[k+1][ir][ic] = max(dp[k+1][ir][ic],dp[k][ir][ic]+itemMap[ir][ic])
        #-位置遷移-#
        for k in range(4):
            dp[0][ir+1][ic] = max(dp[0][ir+1][ic],dp[k][ir][ic])
            dp[k][ir][ic+1] = max(dp[k][ir][ic+1],dp[k][ir][ic]) ic range(C) range C for k in range(2,-1,-1):
            #-拾う拾わない遷移-#
            dp[k+1][ir][ic] = max(dp[k+1][ir][ic],dp[k][ir][ic]+itemMap[ir][ic])
        #-位置遷移-#
         k range(2,-1,-1) range 2 -1 -1 dp[k+1][ir][ic] = max(dp[k+1][ir][ic],dp[k][ir][ic]+itemMap[ir][ic]) dp[k+1][ir][ic] [ir] [k+1] dp k+1 k 1 ir ic max(dp[k+1][ir][ic],dp[k][ir][ic]+itemMap[ir][ic]) max dp[k+1][ir][ic] [ir] [k+1] dp k+1 k 1 ir ic dp[k][ir][ic]+itemMap[ir][ic] dp[k][ir][ic] [ir] [k] dp k ir ic itemMap[ir][ic] [ir] itemMap ir ic for k in range(4):
            dp[0][ir+1][ic] = max(dp[0][ir+1][ic],dp[k][ir][ic])
            dp[k][ir][ic+1] = max(dp[k][ir][ic+1],dp[k][ir][ic]) k range(4) range 4 dp[0][ir+1][ic] = max(dp[0][ir+1][ic],dp[k][ir][ic]) dp[0][ir+1][ic] [ir+1] [0] dp 0 ir+1 ir 1 ic max(dp[0][ir+1][ic],dp[k][ir][ic]) max dp[0][ir+1][ic] [ir+1] [0] dp 0 ir+1 ir 1 ic dp[k][ir][ic] [ir] [k] dp k ir ic dp[k][ir][ic+1] = max(dp[k][ir][ic+1],dp[k][ir][ic]) dp[k][ir][ic+1] [ir] [k] dp k ir ic+1 ic 1 max(dp[k][ir][ic+1],dp[k][ir][ic]) max dp[k][ir][ic+1] [ir] [k] dp k ir ic+1 ic 1 dp[k][ir][ic] [ir] [k] dp k ir ic ans = 0 ans 0 for k in range(4):
    ans = max(ans,dp[k][R-1][C-1]) k range(4) range 4 ans = max(ans,dp[k][R-1][C-1]) ans max(ans,dp[k][R-1][C-1]) max ans dp[k][R-1][C-1] [R-1] [k] dp k R-1 R 1 C-1 C 1 print(ans) print ans v=list(map(int,input().split())) list(map(int,input().split())) v ans = 0 0 ans ans = max(ans,dp[k][R-1][C-1]) max(ans,dp[k][R-1][C-1]) ans itemMap = [[0]*(C+1) for _ in range(R+1)] [[0]*(C+1) for _ in range(R+1)] itemMap r,c,v=list(map(int,input().split())) list(map(int,input().split())) r input = sys.stdin.readline sys.stdin.readline input R,C,K=list(map(int,input().split())) list(map(int,input().split())) R C,K=list(map(int,input().split())) list(map(int,input().split())) C K=list(map(int,input().split())) list(map(int,input().split())) K dp =[[[0]*(C+1) for _ in range(R+1)] for _ in range(4)] [[[0]*(C+1) for _ in range(R+1)] for _ in range(4)] dp c,v=list(map(int,input().split())) list(map(int,input().split())) c
import sys
input = sys.stdin.readline

R,C,K=list(map(int,input().split()))
itemMap = [[0]*(C+1) for _ in range(R+1)]
dp =[[[0]*(C+1) for _ in range(R+1)] for _ in range(4)]

for _ in range(K):
    r,c,v=list(map(int,input().split()))
    itemMap[r-1][c-1]=v

for ir in range(R):
    for ic in range(C):
        for k in range(2,-1,-1):
            #-拾う拾わない遷移-#
            dp[k+1][ir][ic] = max(dp[k+1][ir][ic],dp[k][ir][ic]+itemMap[ir][ic])
        #-位置遷移-#
        for k in range(4):
            dp[0][ir+1][ic] = max(dp[0][ir+1][ic],dp[k][ir][ic])
            dp[k][ir][ic+1] = max(dp[k][ir][ic+1],dp[k][ir][ic])

ans = 0
for k in range(4):
    ans = max(ans,dp[k][R-1][C-1])
print(ans)
                            
                        
