def pri(x):
    for item in x:
        print(item)

r,c,k=map(int,input().split())

fuck=[list(map(int,input().split())) for _ in range(k)]

rck=[[0]*(c+1) for _ in range(r+1)]

for [rr,cc,kk] in fuck:
    rck[rr][cc]=kk
#pri(rck)
#dp[y][x][cnt]

dp=[[0]*4 for _ in range(c+1)]
#print(dp)
for y in range(1,r+1):
    for x in range(1,c+1):
        
        dp[x][0]=max(dp[x-1][0],dp[x][0],dp[x][1],dp[x][2],dp[x][3])
        dp[x][1]=max(dp[x][0]+rck[y][x],dp[x][1],dp[x-1][1])
        dp[x][2]=max(dp[x-1][1]+rck[y][x],dp[x][2],dp[x-1][2],dp[x][1])
        dp[x][3]=max(dp[x-1][2]+rck[y][x],dp[x][3],dp[x-1][3],dp[x][2])
        #print(y,x,dp)

print(max(dp[-1]))
             
              def pri(x):
    for item in x:
        print(item) pri for item in x:
        print(item) item x print(item) print item x x r,c,k=map(int,input().split()) r map(int,input().split()) map int input().split() ().split () input split c k list(map(int,input().split())) for _ in range(k) for _ in range(k) _ range(k) range k for _ in range(k) list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split fuck=[list(map(int,input().split())) for _ in range(k)] fuck [list(map(int,input().split())) for _ in range(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 rck=[[0]*(c+1) for _ in range(r+1)] rck [[0]*(c+1) for _ in range(r+1)] for [rr,cc,kk] in fuck:
    rck[rr][cc]=kk
#pri(rck)
#dp[y][x][cnt] [rr,cc,kk] rr cc kk fuck rck[rr][cc]=kk rck[rr][cc] [rr] rck rr cc kk [0]*4 for _ in range(c+1) for _ in range(c+1) _ range(c+1) range c+1 c 1 for _ in range(c+1) [0]*4 [0] 0 4 dp=[[0]*4 for _ in range(c+1)] dp [[0]*4 for _ in range(c+1)] for y in range(1,r+1):
    for x in range(1,c+1):
        
        dp[x][0]=max(dp[x-1][0],dp[x][0],dp[x][1],dp[x][2],dp[x][3])
        dp[x][1]=max(dp[x][0]+rck[y][x],dp[x][1],dp[x-1][1])
        dp[x][2]=max(dp[x-1][1]+rck[y][x],dp[x][2],dp[x-1][2],dp[x][1])
        dp[x][3]=max(dp[x-1][2]+rck[y][x],dp[x][3],dp[x-1][3],dp[x][2])
        #print(y,x,dp) y range(1,r+1) range 1 r+1 r 1 for x in range(1,c+1):
        
        dp[x][0]=max(dp[x-1][0],dp[x][0],dp[x][1],dp[x][2],dp[x][3])
        dp[x][1]=max(dp[x][0]+rck[y][x],dp[x][1],dp[x-1][1])
        dp[x][2]=max(dp[x-1][1]+rck[y][x],dp[x][2],dp[x-1][2],dp[x][1])
        dp[x][3]=max(dp[x-1][2]+rck[y][x],dp[x][3],dp[x-1][3],dp[x][2])
        #print(y,x,dp) x range(1,c+1) range 1 c+1 c 1 dp[x][0]=max(dp[x-1][0],dp[x][0],dp[x][1],dp[x][2],dp[x][3]) dp[x][0] [x] dp x 0 max(dp[x-1][0],dp[x][0],dp[x][1],dp[x][2],dp[x][3]) max dp[x-1][0] [x-1] dp x-1 x 1 0 dp[x][0] [x] dp x 0 dp[x][1] [x] dp x 1 dp[x][2] [x] dp x 2 dp[x][3] [x] dp x 3 dp[x][1]=max(dp[x][0]+rck[y][x],dp[x][1],dp[x-1][1]) dp[x][1] [x] dp x 1 max(dp[x][0]+rck[y][x],dp[x][1],dp[x-1][1]) max dp[x][0]+rck[y][x] dp[x][0] [x] dp x 0 rck[y][x] [y] rck y x dp[x][1] [x] dp x 1 dp[x-1][1] [x-1] dp x-1 x 1 1 dp[x][2]=max(dp[x-1][1]+rck[y][x],dp[x][2],dp[x-1][2],dp[x][1]) dp[x][2] [x] dp x 2 max(dp[x-1][1]+rck[y][x],dp[x][2],dp[x-1][2],dp[x][1]) max dp[x-1][1]+rck[y][x] dp[x-1][1] [x-1] dp x-1 x 1 1 rck[y][x] [y] rck y x dp[x][2] [x] dp x 2 dp[x-1][2] [x-1] dp x-1 x 1 2 dp[x][1] [x] dp x 1 dp[x][3]=max(dp[x-1][2]+rck[y][x],dp[x][3],dp[x-1][3],dp[x][2]) dp[x][3] [x] dp x 3 max(dp[x-1][2]+rck[y][x],dp[x][3],dp[x-1][3],dp[x][2]) max dp[x-1][2]+rck[y][x] dp[x-1][2] [x-1] dp x-1 x 1 2 rck[y][x] [y] rck y x dp[x][3] [x] dp x 3 dp[x-1][3] [x-1] dp x-1 x 1 3 dp[x][2] [x] dp x 2 print(max(dp[-1])) print max(dp[-1]) max dp[-1] dp -1 c,k=map(int,input().split()) map(int,input().split()) c fuck=[list(map(int,input().split())) for _ in range(k)] [list(map(int,input().split())) for _ in range(k)] fuck r,c,k=map(int,input().split()) map(int,input().split()) r dp=[[0]*4 for _ in range(c+1)] [[0]*4 for _ in range(c+1)] dp def pri(x):
    for item in x:
        print(item) def pri(x):
    for item in x:
        print(item) pri rck=[[0]*(c+1) for _ in range(r+1)] [[0]*(c+1) for _ in range(r+1)] rck k=map(int,input().split()) map(int,input().split()) k
def pri(x):
    for item in x:
        print(item)

r,c,k=map(int,input().split())

fuck=[list(map(int,input().split())) for _ in range(k)]

rck=[[0]*(c+1) for _ in range(r+1)]

for [rr,cc,kk] in fuck:
    rck[rr][cc]=kk
#pri(rck)
#dp[y][x][cnt]

dp=[[0]*4 for _ in range(c+1)]
#print(dp)
for y in range(1,r+1):
    for x in range(1,c+1):
        
        dp[x][0]=max(dp[x-1][0],dp[x][0],dp[x][1],dp[x][2],dp[x][3])
        dp[x][1]=max(dp[x][0]+rck[y][x],dp[x][1],dp[x-1][1])
        dp[x][2]=max(dp[x-1][1]+rck[y][x],dp[x][2],dp[x-1][2],dp[x][1])
        dp[x][3]=max(dp[x-1][2]+rck[y][x],dp[x][3],dp[x-1][3],dp[x][2])
        #print(y,x,dp)

print(max(dp[-1]))
             
             
