# -*- coding: utf-8 -*-
import sys 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

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

dp = [0] * (C+1)
dp[0] = 0

for i in range(1,R+1):
    ndp = [0] * (C+1)
    row = V[i]
    ldp = [0] * 4
    for j in range(1,C+1):
        # ldp[0] = max(ldp[0], dp[j])
        ldp[0] = dp[j]
        for k in range(2,-1,-1):
            ldp[k+1] = max(ldp[k+1], ldp[k] + row[j]) # 取る場合と取らない場合
        ndp[j] = max(ldp)
    dp = ndp
print(dp[C]) import sys sys read = sys.stdin.buffer.read read sys.stdin.buffer.read sys.stdin.buffer sys.stdin sys stdin buffer read readline = sys.stdin.buffer.readline readline sys.stdin.buffer.readline sys.stdin.buffer sys.stdin sys stdin buffer readline readlines = sys.stdin.buffer.readlines readlines sys.stdin.buffer.readlines sys.stdin.buffer sys.stdin sys stdin buffer readlines R, C, K = map(int, readline().split()) R map(int, readline().split()) map int readline().split() ().split () readline 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 V = [[0]*(C+1) for _ in range(R+1)] V [[0]*(C+1) for _ in range(R+1)] for i in range(K):
    r,c,v = map(int,readline().split())
    V[r][c] = v i range(K) range K r,c,v = map(int,readline().split()) r map(int,readline().split()) map int readline().split() ().split () readline split c v V[r][c] = v V[r][c] [r] V r c v dp = [0] * (C+1) dp [0] * (C+1) [0] 0 C+1 C 1 dp[0] = 0 dp[0] dp 0 0 for i in range(1,R+1):
    ndp = [0] * (C+1)
    row = V[i]
    ldp = [0] * 4
    for j in range(1,C+1):
        # ldp[0] = max(ldp[0], dp[j])
        ldp[0] = dp[j]
        for k in range(2,-1,-1):
            ldp[k+1] = max(ldp[k+1], ldp[k] + row[j]) # 取る場合と取らない場合
        ndp[j] = max(ldp)
    dp = ndp i range(1,R+1) range 1 R+1 R 1 ndp = [0] * (C+1) ndp [0] * (C+1) [0] 0 C+1 C 1 row = V[i] row V[i] V i ldp = [0] * 4 ldp [0] * 4 [0] 0 4 for j in range(1,C+1):
        # ldp[0] = max(ldp[0], dp[j])
        ldp[0] = dp[j]
        for k in range(2,-1,-1):
            ldp[k+1] = max(ldp[k+1], ldp[k] + row[j]) # 取る場合と取らない場合
        ndp[j] = max(ldp)
     j range(1,C+1) range 1 C+1 C 1 ldp[0] = dp[j] ldp[0] ldp 0 dp[j] dp j for k in range(2,-1,-1):
            ldp[k+1] = max(ldp[k+1], ldp[k] + row[j]) # 取る場合と取らない場合
         k range(2,-1,-1) range 2 -1 -1 ldp[k+1] = max(ldp[k+1], ldp[k] + row[j]) ldp[k+1] ldp k+1 k 1 max(ldp[k+1], ldp[k] + row[j]) max ldp[k+1] ldp k+1 k 1 ldp[k] + row[j] ldp[k] ldp k row[j] row j ndp[j] = max(ldp) ndp[j] ndp j max(ldp) max ldp dp = ndp dp ndp print(dp[C]) print dp[C] dp C dp = ndp ndp dp readlines = sys.stdin.buffer.readlines sys.stdin.buffer.readlines readlines C, K = map(int, readline().split()) map(int, readline().split()) C r,c,v = map(int,readline().split()) map(int,readline().split()) r V = [[0]*(C+1) for _ in range(R+1)] [[0]*(C+1) for _ in range(R+1)] V v = map(int,readline().split()) map(int,readline().split()) v c,v = map(int,readline().split()) map(int,readline().split()) c row = V[i] V[i] row ldp = [0] * 4 [0] * 4 ldp R, C, K = map(int, readline().split()) map(int, readline().split()) R dp = [0] * (C+1) [0] * (C+1) dp ndp = [0] * (C+1) [0] * (C+1) ndp read = sys.stdin.buffer.read sys.stdin.buffer.read read K = map(int, readline().split()) map(int, readline().split()) K readline = sys.stdin.buffer.readline sys.stdin.buffer.readline readline
# -*- coding: utf-8 -*-
import sys 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

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

dp = [0] * (C+1)
dp[0] = 0

for i in range(1,R+1):
    ndp = [0] * (C+1)
    row = V[i]
    ldp = [0] * 4
    for j in range(1,C+1):
        # ldp[0] = max(ldp[0], dp[j])
        ldp[0] = dp[j]
        for k in range(2,-1,-1):
            ldp[k+1] = max(ldp[k+1], ldp[k] + row[j]) # 取る場合と取らない場合
        ndp[j] = max(ldp)
    dp = ndp
print(dp[C])