import sys
input=sys.stdin.readline
def main():
    r,c,k=map(int,input().split())
    v=[[0]*c for _ in range(r)]
    for _ in range(k):
        ri,ci,a=map(int,input().split())
        ri-=1
        ci-=1
        v[ri][ci]=a
    dp=[[[0]*c for _ in range(r)] for i in range(4)]
    #print(dp)
    if v[0][0]>0:
        dp[1][0][0]=v[0][0]
    for i in range(r):
        for j in range(c):
            for k in range(4):
                if i>0:
                    dp[1][i][j]=max(dp[1][i][j],dp[k][i-1][j]+v[i][j])
                    dp[0][i][j]=max(dp[0][i][j],dp[k][i-1][j])
                if j>0:
                    if k>0:
                        dp[k][i][j]=max(dp[k][i][j],dp[k-1][i][j-1]+v[i][j])
                    dp[k][i][j]=max(dp[k][i][j],dp[k][i][j-1])
    #print(dp)
    ans=0
    for i in range(4):
        ans=max(dp[i][r-1][c-1],ans)
    return print(ans)
if __name__=="__main__":
    main() import sys sys input=sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline def main():
    r,c,k=map(int,input().split())
    v=[[0]*c for _ in range(r)]
    for _ in range(k):
        ri,ci,a=map(int,input().split())
        ri-=1
        ci-=1
        v[ri][ci]=a
    dp=[[[0]*c for _ in range(r)] for i in range(4)]
    #print(dp)
    if v[0][0]>0:
        dp[1][0][0]=v[0][0]
    for i in range(r):
        for j in range(c):
            for k in range(4):
                if i>0:
                    dp[1][i][j]=max(dp[1][i][j],dp[k][i-1][j]+v[i][j])
                    dp[0][i][j]=max(dp[0][i][j],dp[k][i-1][j])
                if j>0:
                    if k>0:
                        dp[k][i][j]=max(dp[k][i][j],dp[k-1][i][j-1]+v[i][j])
                    dp[k][i][j]=max(dp[k][i][j],dp[k][i][j-1])
    #print(dp)
    ans=0
    for i in range(4):
        ans=max(dp[i][r-1][c-1],ans)
    return print(ans) main 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) for _ in range(r) _ range(r) range r for _ in range(r) [0]*c [0] 0 c v=[[0]*c for _ in range(r)] v [[0]*c for _ in range(r)] for _ in range(k):
        ri,ci,a=map(int,input().split())
        ri-=1
        ci-=1
        v[ri][ci]=a
     _ range(k) range k ri,ci,a=map(int,input().split()) ri map(int,input().split()) map int input().split() ().split () input split ci a ri-=1 ri 1 ci-=1 ci 1 v[ri][ci]=a v[ri][ci] [ri] v ri ci a [[0]*c for _ in range(r)] for i in range(4) for i in range(4) i range(4) range 4 for i in range(4) [[0]*c for _ in range(r)] dp=[[[0]*c for _ in range(r)] for i in range(4)] dp [[[0]*c for _ in range(r)] for i in range(4)] if v[0][0]>0:
        dp[1][0][0]=v[0][0]
     v[0][0]>0 v[0][0] [0] v 0 0 0 dp[1][0][0]=v[0][0] dp[1][0][0] [0] [1] dp 1 0 0 v[0][0] [0] v 0 0 for i in range(r):
        for j in range(c):
            for k in range(4):
                if i>0:
                    dp[1][i][j]=max(dp[1][i][j],dp[k][i-1][j]+v[i][j])
                    dp[0][i][j]=max(dp[0][i][j],dp[k][i-1][j])
                if j>0:
                    if k>0:
                        dp[k][i][j]=max(dp[k][i][j],dp[k-1][i][j-1]+v[i][j])
                    dp[k][i][j]=max(dp[k][i][j],dp[k][i][j-1])
    #print(dp)
     i range(r) range r for j in range(c):
            for k in range(4):
                if i>0:
                    dp[1][i][j]=max(dp[1][i][j],dp[k][i-1][j]+v[i][j])
                    dp[0][i][j]=max(dp[0][i][j],dp[k][i-1][j])
                if j>0:
                    if k>0:
                        dp[k][i][j]=max(dp[k][i][j],dp[k-1][i][j-1]+v[i][j])
                    dp[k][i][j]=max(dp[k][i][j],dp[k][i][j-1])
    #print(dp)
     j range(c) range c for k in range(4):
                if i>0:
                    dp[1][i][j]=max(dp[1][i][j],dp[k][i-1][j]+v[i][j])
                    dp[0][i][j]=max(dp[0][i][j],dp[k][i-1][j])
                if j>0:
                    if k>0:
                        dp[k][i][j]=max(dp[k][i][j],dp[k-1][i][j-1]+v[i][j])
                    dp[k][i][j]=max(dp[k][i][j],dp[k][i][j-1])
    #print(dp)
     k range(4) range 4 if i>0:
                    dp[1][i][j]=max(dp[1][i][j],dp[k][i-1][j]+v[i][j])
                    dp[0][i][j]=max(dp[0][i][j],dp[k][i-1][j])
                 i>0 i 0 dp[1][i][j]=max(dp[1][i][j],dp[k][i-1][j]+v[i][j]) dp[1][i][j] [i] [1] dp 1 i j max(dp[1][i][j],dp[k][i-1][j]+v[i][j]) max dp[1][i][j] [i] [1] dp 1 i j dp[k][i-1][j]+v[i][j] dp[k][i-1][j] [i-1] [k] dp k i-1 i 1 j v[i][j] [i] v i j 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 if j>0:
                    if k>0:
                        dp[k][i][j]=max(dp[k][i][j],dp[k-1][i][j-1]+v[i][j])
                    dp[k][i][j]=max(dp[k][i][j],dp[k][i][j-1])
    #print(dp)
     j>0 j 0 if k>0:
                        dp[k][i][j]=max(dp[k][i][j],dp[k-1][i][j-1]+v[i][j])
                     k>0 k 0 dp[k][i][j]=max(dp[k][i][j],dp[k-1][i][j-1]+v[i][j]) dp[k][i][j] [i] [k] dp k i j max(dp[k][i][j],dp[k-1][i][j-1]+v[i][j]) max dp[k][i][j] [i] [k] dp k i j dp[k-1][i][j-1]+v[i][j] dp[k-1][i][j-1] [i] [k-1] dp k-1 k 1 i j-1 j 1 v[i][j] [i] v i j 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 ans=0 ans 0 for i in range(4):
        ans=max(dp[i][r-1][c-1],ans)
     i range(4) range 4 ans=max(dp[i][r-1][c-1],ans) ans max(dp[i][r-1][c-1],ans) max dp[i][r-1][c-1] [r-1] [i] dp i r-1 r 1 c-1 c 1 ans return print(ans) print(ans) print ans if __name__=="__main__":
    main() __name__=="__main__" __name__ "__main__" main() main input=sys.stdin.readline sys.stdin.readline input def main():
    r,c,k=map(int,input().split())
    v=[[0]*c for _ in range(r)]
    for _ in range(k):
        ri,ci,a=map(int,input().split())
        ri-=1
        ci-=1
        v[ri][ci]=a
    dp=[[[0]*c for _ in range(r)] for i in range(4)]
    #print(dp)
    if v[0][0]>0:
        dp[1][0][0]=v[0][0]
    for i in range(r):
        for j in range(c):
            for k in range(4):
                if i>0:
                    dp[1][i][j]=max(dp[1][i][j],dp[k][i-1][j]+v[i][j])
                    dp[0][i][j]=max(dp[0][i][j],dp[k][i-1][j])
                if j>0:
                    if k>0:
                        dp[k][i][j]=max(dp[k][i][j],dp[k-1][i][j-1]+v[i][j])
                    dp[k][i][j]=max(dp[k][i][j],dp[k][i][j-1])
    #print(dp)
    ans=0
    for i in range(4):
        ans=max(dp[i][r-1][c-1],ans)
    return print(ans) def main():
    r,c,k=map(int,input().split())
    v=[[0]*c for _ in range(r)]
    for _ in range(k):
        ri,ci,a=map(int,input().split())
        ri-=1
        ci-=1
        v[ri][ci]=a
    dp=[[[0]*c for _ in range(r)] for i in range(4)]
    #print(dp)
    if v[0][0]>0:
        dp[1][0][0]=v[0][0]
    for i in range(r):
        for j in range(c):
            for k in range(4):
                if i>0:
                    dp[1][i][j]=max(dp[1][i][j],dp[k][i-1][j]+v[i][j])
                    dp[0][i][j]=max(dp[0][i][j],dp[k][i-1][j])
                if j>0:
                    if k>0:
                        dp[k][i][j]=max(dp[k][i][j],dp[k-1][i][j-1]+v[i][j])
                    dp[k][i][j]=max(dp[k][i][j],dp[k][i][j-1])
    #print(dp)
    ans=0
    for i in range(4):
        ans=max(dp[i][r-1][c-1],ans)
    return print(ans) main
import sys
input=sys.stdin.readline
def main():
    r,c,k=map(int,input().split())
    v=[[0]*c for _ in range(r)]
    for _ in range(k):
        ri,ci,a=map(int,input().split())
        ri-=1
        ci-=1
        v[ri][ci]=a
    dp=[[[0]*c for _ in range(r)] for i in range(4)]
    #print(dp)
    if v[0][0]>0:
        dp[1][0][0]=v[0][0]
    for i in range(r):
        for j in range(c):
            for k in range(4):
                if i>0:
                    dp[1][i][j]=max(dp[1][i][j],dp[k][i-1][j]+v[i][j])
                    dp[0][i][j]=max(dp[0][i][j],dp[k][i-1][j])
                if j>0:
                    if k>0:
                        dp[k][i][j]=max(dp[k][i][j],dp[k-1][i][j-1]+v[i][j])
                    dp[k][i][j]=max(dp[k][i][j],dp[k][i][j-1])
    #print(dp)
    ans=0
    for i in range(4):
        ans=max(dp[i][r-1][c-1],ans)
    return print(ans)
if __name__=="__main__":
    main()