import sys
from pprint import pprint

R,C,K=map(int,input().split())

grid=[[0]*C for _ in range(R+1)]
for _ in range(K):
    r,c,v=map(int,input().split())
    grid[r][c-1]=v

for i in range(1,R+1):
    cell=[0]*4
    for j in range(C):
        cell[0]=max(cell[0],grid[i-1][j])
        for k in range(2,-1,-1):
            cell[k+1]=max(cell[k+1],cell[k]+grid[i][j])
        grid[i][j]=max(cell)

print(grid[-1][-1]) import sys sys from pprint import pprint R,C,K=map(int,input().split()) R map(int,input().split()) map int input().split() ().split () input split C K [0]*C 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 [0] 0 C grid=[[0]*C for _ in range(R+1)] grid [[0]*C for _ in range(R+1)] for _ in range(K):
    r,c,v=map(int,input().split())
    grid[r][c-1]=v _ range(K) range K r,c,v=map(int,input().split()) r map(int,input().split()) map int input().split() ().split () input split c v grid[r][c-1]=v grid[r][c-1] [r] grid r c-1 c 1 v for i in range(1,R+1):
    cell=[0]*4
    for j in range(C):
        cell[0]=max(cell[0],grid[i-1][j])
        for k in range(2,-1,-1):
            cell[k+1]=max(cell[k+1],cell[k]+grid[i][j])
        grid[i][j]=max(cell) i range(1,R+1) range 1 R+1 R 1 cell=[0]*4 cell [0]*4 [0] 0 4 for j in range(C):
        cell[0]=max(cell[0],grid[i-1][j])
        for k in range(2,-1,-1):
            cell[k+1]=max(cell[k+1],cell[k]+grid[i][j])
        grid[i][j]=max(cell) j range(C) range C cell[0]=max(cell[0],grid[i-1][j]) cell[0] cell 0 max(cell[0],grid[i-1][j]) max cell[0] cell 0 grid[i-1][j] [i-1] grid i-1 i 1 j for k in range(2,-1,-1):
            cell[k+1]=max(cell[k+1],cell[k]+grid[i][j])
         k range(2,-1,-1) range 2 -1 -1 cell[k+1]=max(cell[k+1],cell[k]+grid[i][j]) cell[k+1] cell k+1 k 1 max(cell[k+1],cell[k]+grid[i][j]) max cell[k+1] cell k+1 k 1 cell[k]+grid[i][j] cell[k] cell k grid[i][j] [i] grid i j grid[i][j]=max(cell) grid[i][j] [i] grid i j max(cell) max cell print(grid[-1][-1]) print grid[-1][-1] [-1] grid -1 -1 C,K=map(int,input().split()) map(int,input().split()) C K=map(int,input().split()) map(int,input().split()) K r,c,v=map(int,input().split()) map(int,input().split()) r R,C,K=map(int,input().split()) map(int,input().split()) R v=map(int,input().split()) map(int,input().split()) v cell=[0]*4 [0]*4 cell grid=[[0]*C for _ in range(R+1)] [[0]*C for _ in range(R+1)] grid c,v=map(int,input().split()) map(int,input().split()) c
import sys
from pprint import pprint

R,C,K=map(int,input().split())

grid=[[0]*C for _ in range(R+1)]
for _ in range(K):
    r,c,v=map(int,input().split())
    grid[r][c-1]=v

for i in range(1,R+1):
    cell=[0]*4
    for j in range(C):
        cell[0]=max(cell[0],grid[i-1][j])
        for k in range(2,-1,-1):
            cell[k+1]=max(cell[k+1],cell[k]+grid[i][j])
        grid[i][j]=max(cell)

print(grid[-1][-1])
