import sys
input = sys.stdin.readline

r, c, k = map(int, input().split())
v = [[0 for j in range(c)] for i in range(r)]

dp = [[[0 for j in range(c)] for i in range(r)] for k in range(4)]

for i in range(k):
    ri, ci, vi = map(int, input().split())
    v[ri-1][ci-1] = vi


for i in range(r):
    if i > 0:
        for j in range(c):
            for k in range(4):
                dp[0][i][j] = max(dp[0][i][j], dp[k][i-1][j])
    for j in range(c):
        if j > 0:
            for k in range(4):
                dp[k][i][j] = max(dp[k][i][j], dp[k][i][j-1])
        if v[i][j]:
            for k in reversed(range(1, 4)):
                dp[k][i][j] = max(dp[k][i][j], dp[k-1][i][j]+v[i][j])
        

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 = map(int, input().split()) r map(int, input().split()) map int input().split() ().split () input split c k [0 for j in range(c)] for i in range(r) for i in range(r) i range(r) range r for i in range(r) [0 for j in range(c)] v = [[0 for j in range(c)] for i in range(r)] v [[0 for j in range(c)] for i in range(r)] [[0 for j in range(c)] for i in range(r)] for k in range(4) for k in range(4) k range(4) range 4 for k in range(4) [[0 for j in range(c)] for i in range(r)] dp = [[[0 for j in range(c)] for i in range(r)] for k in range(4)] dp [[[0 for j in range(c)] for i in range(r)] for k in range(4)] for i in range(k):
    ri, ci, vi = map(int, input().split())
    v[ri-1][ci-1] = vi i range(k) range k ri, ci, vi = map(int, input().split()) ri map(int, input().split()) map int input().split() ().split () input split ci vi v[ri-1][ci-1] = vi v[ri-1][ci-1] [ri-1] v ri-1 ri 1 ci-1 ci 1 vi for i in range(r):
    if i > 0:
        for j in range(c):
            for k in range(4):
                dp[0][i][j] = max(dp[0][i][j], dp[k][i-1][j])
    for j in range(c):
        if j > 0:
            for k in range(4):
                dp[k][i][j] = max(dp[k][i][j], dp[k][i][j-1])
        if v[i][j]:
            for k in reversed(range(1, 4)):
                dp[k][i][j] = max(dp[k][i][j], dp[k-1][i][j]+v[i][j])
         i range(r) range r if i > 0:
        for j in range(c):
            for k in range(4):
                dp[0][i][j] = max(dp[0][i][j], dp[k][i-1][j])
     i > 0 i 0 for j in range(c):
            for k in range(4):
                dp[0][i][j] = max(dp[0][i][j], dp[k][i-1][j])
     j range(c) range c for k in range(4):
                dp[0][i][j] = max(dp[0][i][j], dp[k][i-1][j])
     k range(4) range 4 dp[0][i][j] = max(dp[0][i][j], dp[k][i-1][j]) dp[0][i][j] [i] [0] dp 0 i j max(dp[0][i][j], dp[k][i-1][j]) max dp[0][i][j] [i] [0] dp 0 i j dp[k][i-1][j] [i-1] [k] dp k i-1 i 1 j for j in range(c):
        if j > 0:
            for k in range(4):
                dp[k][i][j] = max(dp[k][i][j], dp[k][i][j-1])
        if v[i][j]:
            for k in reversed(range(1, 4)):
                dp[k][i][j] = max(dp[k][i][j], dp[k-1][i][j]+v[i][j])
         j range(c) range c if j > 0:
            for k in range(4):
                dp[k][i][j] = max(dp[k][i][j], dp[k][i][j-1])
         j > 0 j 0 for k in range(4):
                dp[k][i][j] = max(dp[k][i][j], dp[k][i][j-1])
         k range(4) range 4 dp[k][i][j] = max(dp[k][i][j], dp[k][i][j-1]) dp[k][i][j] [i] [k] dp k i j max(dp[k][i][j], dp[k][i][j-1]) max dp[k][i][j] [i] [k] dp k i j dp[k][i][j-1] [i] [k] dp k i j-1 j 1 if v[i][j]:
            for k in reversed(range(1, 4)):
                dp[k][i][j] = max(dp[k][i][j], dp[k-1][i][j]+v[i][j])
         v[i][j] [i] v i j for k in reversed(range(1, 4)):
                dp[k][i][j] = max(dp[k][i][j], dp[k-1][i][j]+v[i][j])
         k reversed(range(1, 4)) reversed range(1, 4) range 1 4 dp[k][i][j] = max(dp[k][i][j], dp[k-1][i][j]+v[i][j]) dp[k][i][j] [i] [k] dp k i j max(dp[k][i][j], dp[k-1][i][j]+v[i][j]) max dp[k][i][j] [i] [k] dp k i j dp[k-1][i][j]+v[i][j] dp[k-1][i][j] [i] [k-1] dp k-1 k 1 i j v[i][j] [i] v i j 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 = [[0 for j in range(c)] for i in range(r)] [[0 for j in range(c)] for i in range(r)] v vi = map(int, input().split()) map(int, input().split()) vi ans = 0 0 ans c, k = map(int, input().split()) map(int, input().split()) c ans = max(ans, dp[k][r-1][c-1]) max(ans, dp[k][r-1][c-1]) ans ri, ci, vi = map(int, input().split()) map(int, input().split()) ri r, c, k = map(int, input().split()) map(int, input().split()) r k = map(int, input().split()) map(int, input().split()) k dp = [[[0 for j in range(c)] for i in range(r)] for k in range(4)] [[[0 for j in range(c)] for i in range(r)] for k in range(4)] dp ci, vi = map(int, input().split()) map(int, input().split()) ci input = sys.stdin.readline sys.stdin.readline input
import sys
input = sys.stdin.readline

r, c, k = map(int, input().split())
v = [[0 for j in range(c)] for i in range(r)]

dp = [[[0 for j in range(c)] for i in range(r)] for k in range(4)]

for i in range(k):
    ri, ci, vi = map(int, input().split())
    v[ri-1][ci-1] = vi


for i in range(r):
    if i > 0:
        for j in range(c):
            for k in range(4):
                dp[0][i][j] = max(dp[0][i][j], dp[k][i-1][j])
    for j in range(c):
        if j > 0:
            for k in range(4):
                dp[k][i][j] = max(dp[k][i][j], dp[k][i][j-1])
        if v[i][j]:
            for k in reversed(range(1, 4)):
                dp[k][i][j] = max(dp[k][i][j], dp[k-1][i][j]+v[i][j])
        

ans = 0

for k in range(4):
    ans = max(ans, dp[k][r-1][c-1])

print(ans)
        
