import sys


def input():
    return sys.stdin.readline().rstrip()


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

    field = [[0 for j in range(C)] for i in range(R)]

    for _ in range(K):
        r, c, v = map(int, input().split())
        field[r - 1][c - 1] = v

    dp = [[[0] * C for j in range(R)] for i in range(4)]

    for i in range(R):
        for j in range(C):
            ct = field[i ][j ]
            pm = max(dp[0][i-1][j],dp[1][i-1][j],dp[2][i-1][j],dp[3][i-1][j])
            if ct == 0:
                dp[0][i][j] = max(dp[0][i][j-1],pm)

                for k in range(1, 4):
                    if j>0:
                        dp[k][i][j] = dp[k][i][j - 1]
            else:
                dp[0][i][j] = max(dp[0][i][j - 1],pm)
                dp[1][i][j] = max(ct + max(dp[0][i][j - 1], pm),dp[1][i][j-1])
                for k in range(2, 4):
                    if j >0:
                        dp[k][i][j] = max(dp[k - 1][i][j - 1] +ct,dp[k][i][j-1])

    print(max(dp[0][R-1][C-1],dp[1][R-1][C-1],dp[2][R-1][C-1],dp[3][R-1][C-1]))

if __name__ == "__main__":
    main() import sys sys def input():
    return sys.stdin.readline().rstrip() input return sys.stdin.readline().rstrip() sys.stdin.readline().rstrip() sys.stdin.readline().rstrip sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline rstrip def main():
    R, C, K = map(int, input().split())

    field = [[0 for j in range(C)] for i in range(R)]

    for _ in range(K):
        r, c, v = map(int, input().split())
        field[r - 1][c - 1] = v

    dp = [[[0] * C for j in range(R)] for i in range(4)]

    for i in range(R):
        for j in range(C):
            ct = field[i ][j ]
            pm = max(dp[0][i-1][j],dp[1][i-1][j],dp[2][i-1][j],dp[3][i-1][j])
            if ct == 0:
                dp[0][i][j] = max(dp[0][i][j-1],pm)

                for k in range(1, 4):
                    if j>0:
                        dp[k][i][j] = dp[k][i][j - 1]
            else:
                dp[0][i][j] = max(dp[0][i][j - 1],pm)
                dp[1][i][j] = max(ct + max(dp[0][i][j - 1], pm),dp[1][i][j-1])
                for k in range(2, 4):
                    if j >0:
                        dp[k][i][j] = max(dp[k - 1][i][j - 1] +ct,dp[k][i][j-1])

    print(max(dp[0][R-1][C-1],dp[1][R-1][C-1],dp[2][R-1][C-1],dp[3][R-1][C-1])) main 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)] field = [[0 for j in range(C)] for i in range(R)] field [[0 for j in range(C)] for i in range(R)] for _ in range(K):
        r, c, v = map(int, input().split())
        field[r - 1][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 field[r - 1][c - 1] = v field[r - 1][c - 1] [r - 1] field r - 1 r 1 c - 1 c 1 v [[0] * C for j 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 j in range(R)] dp = [[[0] * C for j in range(R)] for i in range(4)] dp [[[0] * C for j in range(R)] for i in range(4)] for i in range(R):
        for j in range(C):
            ct = field[i ][j ]
            pm = max(dp[0][i-1][j],dp[1][i-1][j],dp[2][i-1][j],dp[3][i-1][j])
            if ct == 0:
                dp[0][i][j] = max(dp[0][i][j-1],pm)

                for k in range(1, 4):
                    if j>0:
                        dp[k][i][j] = dp[k][i][j - 1]
            else:
                dp[0][i][j] = max(dp[0][i][j - 1],pm)
                dp[1][i][j] = max(ct + max(dp[0][i][j - 1], pm),dp[1][i][j-1])
                for k in range(2, 4):
                    if j >0:
                        dp[k][i][j] = max(dp[k - 1][i][j - 1] +ct,dp[k][i][j-1])

     i range(R) range R for j in range(C):
            ct = field[i ][j ]
            pm = max(dp[0][i-1][j],dp[1][i-1][j],dp[2][i-1][j],dp[3][i-1][j])
            if ct == 0:
                dp[0][i][j] = max(dp[0][i][j-1],pm)

                for k in range(1, 4):
                    if j>0:
                        dp[k][i][j] = dp[k][i][j - 1]
            else:
                dp[0][i][j] = max(dp[0][i][j - 1],pm)
                dp[1][i][j] = max(ct + max(dp[0][i][j - 1], pm),dp[1][i][j-1])
                for k in range(2, 4):
                    if j >0:
                        dp[k][i][j] = max(dp[k - 1][i][j - 1] +ct,dp[k][i][j-1])

     j range(C) range C ct = field[i ][j ] ct field[i ][j ] [i ] field i j pm = max(dp[0][i-1][j],dp[1][i-1][j],dp[2][i-1][j],dp[3][i-1][j]) pm max(dp[0][i-1][j],dp[1][i-1][j],dp[2][i-1][j],dp[3][i-1][j]) max dp[0][i-1][j] [i-1] [0] dp 0 i-1 i 1 j dp[1][i-1][j] [i-1] [1] dp 1 i-1 i 1 j dp[2][i-1][j] [i-1] [2] dp 2 i-1 i 1 j dp[3][i-1][j] [i-1] [3] dp 3 i-1 i 1 j if ct == 0:
                dp[0][i][j] = max(dp[0][i][j-1],pm)

                for k in range(1, 4):
                    if j>0:
                        dp[k][i][j] = dp[k][i][j - 1]
            else:
                dp[0][i][j] = max(dp[0][i][j - 1],pm)
                dp[1][i][j] = max(ct + max(dp[0][i][j - 1], pm),dp[1][i][j-1])
                for k in range(2, 4):
                    if j >0:
                        dp[k][i][j] = max(dp[k - 1][i][j - 1] +ct,dp[k][i][j-1])

     ct == 0 ct 0 dp[0][i][j] = max(dp[0][i][j-1],pm) dp[0][i][j] [i] [0] dp 0 i j max(dp[0][i][j-1],pm) max dp[0][i][j-1] [i] [0] dp 0 i j-1 j 1 pm for k in range(1, 4):
                    if j>0:
                        dp[k][i][j] = dp[k][i][j - 1]
             k range(1, 4) range 1 4 if j>0:
                        dp[k][i][j] = dp[k][i][j - 1]
             j>0 j 0 dp[k][i][j] = dp[k][i][j - 1] dp[k][i][j] [i] [k] dp k i j dp[k][i][j - 1] [i] [k] dp k i j - 1 j 1 dp[0][i][j] = max(dp[0][i][j - 1],pm) dp[0][i][j] [i] [0] dp 0 i j max(dp[0][i][j - 1],pm) max dp[0][i][j - 1] [i] [0] dp 0 i j - 1 j 1 pm dp[1][i][j] = max(ct + max(dp[0][i][j - 1], pm),dp[1][i][j-1]) dp[1][i][j] [i] [1] dp 1 i j max(ct + max(dp[0][i][j - 1], pm),dp[1][i][j-1]) max ct + max(dp[0][i][j - 1], pm) ct max(dp[0][i][j - 1], pm) max dp[0][i][j - 1] [i] [0] dp 0 i j - 1 j 1 pm dp[1][i][j-1] [i] [1] dp 1 i j-1 j 1 for k in range(2, 4):
                    if j >0:
                        dp[k][i][j] = max(dp[k - 1][i][j - 1] +ct,dp[k][i][j-1])

     k range(2, 4) range 2 4 if j >0:
                        dp[k][i][j] = max(dp[k - 1][i][j - 1] +ct,dp[k][i][j-1])

     j >0 j 0 dp[k][i][j] = max(dp[k - 1][i][j - 1] +ct,dp[k][i][j-1]) dp[k][i][j] [i] [k] dp k i j max(dp[k - 1][i][j - 1] +ct,dp[k][i][j-1]) max dp[k - 1][i][j - 1] +ct dp[k - 1][i][j - 1] [i] [k - 1] dp k - 1 k 1 i j - 1 j 1 ct dp[k][i][j-1] [i] [k] dp k i j-1 j 1 print(max(dp[0][R-1][C-1],dp[1][R-1][C-1],dp[2][R-1][C-1],dp[3][R-1][C-1])) print max(dp[0][R-1][C-1],dp[1][R-1][C-1],dp[2][R-1][C-1],dp[3][R-1][C-1]) max dp[0][R-1][C-1] [R-1] [0] dp 0 R-1 R 1 C-1 C 1 dp[1][R-1][C-1] [R-1] [1] dp 1 R-1 R 1 C-1 C 1 dp[2][R-1][C-1] [R-1] [2] dp 2 R-1 R 1 C-1 C 1 dp[3][R-1][C-1] [R-1] [3] dp 3 R-1 R 1 C-1 C 1 if __name__ == "__main__":
    main() __name__ == "__main__" __name__ "__main__" main() main def main():
    R, C, K = map(int, input().split())

    field = [[0 for j in range(C)] for i in range(R)]

    for _ in range(K):
        r, c, v = map(int, input().split())
        field[r - 1][c - 1] = v

    dp = [[[0] * C for j in range(R)] for i in range(4)]

    for i in range(R):
        for j in range(C):
            ct = field[i ][j ]
            pm = max(dp[0][i-1][j],dp[1][i-1][j],dp[2][i-1][j],dp[3][i-1][j])
            if ct == 0:
                dp[0][i][j] = max(dp[0][i][j-1],pm)

                for k in range(1, 4):
                    if j>0:
                        dp[k][i][j] = dp[k][i][j - 1]
            else:
                dp[0][i][j] = max(dp[0][i][j - 1],pm)
                dp[1][i][j] = max(ct + max(dp[0][i][j - 1], pm),dp[1][i][j-1])
                for k in range(2, 4):
                    if j >0:
                        dp[k][i][j] = max(dp[k - 1][i][j - 1] +ct,dp[k][i][j-1])

    print(max(dp[0][R-1][C-1],dp[1][R-1][C-1],dp[2][R-1][C-1],dp[3][R-1][C-1])) def main():
    R, C, K = map(int, input().split())

    field = [[0 for j in range(C)] for i in range(R)]

    for _ in range(K):
        r, c, v = map(int, input().split())
        field[r - 1][c - 1] = v

    dp = [[[0] * C for j in range(R)] for i in range(4)]

    for i in range(R):
        for j in range(C):
            ct = field[i ][j ]
            pm = max(dp[0][i-1][j],dp[1][i-1][j],dp[2][i-1][j],dp[3][i-1][j])
            if ct == 0:
                dp[0][i][j] = max(dp[0][i][j-1],pm)

                for k in range(1, 4):
                    if j>0:
                        dp[k][i][j] = dp[k][i][j - 1]
            else:
                dp[0][i][j] = max(dp[0][i][j - 1],pm)
                dp[1][i][j] = max(ct + max(dp[0][i][j - 1], pm),dp[1][i][j-1])
                for k in range(2, 4):
                    if j >0:
                        dp[k][i][j] = max(dp[k - 1][i][j - 1] +ct,dp[k][i][j-1])

    print(max(dp[0][R-1][C-1],dp[1][R-1][C-1],dp[2][R-1][C-1],dp[3][R-1][C-1])) main def input():
    return sys.stdin.readline().rstrip() def input():
    return sys.stdin.readline().rstrip() input
import sys


def input():
    return sys.stdin.readline().rstrip()


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

    field = [[0 for j in range(C)] for i in range(R)]

    for _ in range(K):
        r, c, v = map(int, input().split())
        field[r - 1][c - 1] = v

    dp = [[[0] * C for j in range(R)] for i in range(4)]

    for i in range(R):
        for j in range(C):
            ct = field[i ][j ]
            pm = max(dp[0][i-1][j],dp[1][i-1][j],dp[2][i-1][j],dp[3][i-1][j])
            if ct == 0:
                dp[0][i][j] = max(dp[0][i][j-1],pm)

                for k in range(1, 4):
                    if j>0:
                        dp[k][i][j] = dp[k][i][j - 1]
            else:
                dp[0][i][j] = max(dp[0][i][j - 1],pm)
                dp[1][i][j] = max(ct + max(dp[0][i][j - 1], pm),dp[1][i][j-1])
                for k in range(2, 4):
                    if j >0:
                        dp[k][i][j] = max(dp[k - 1][i][j - 1] +ct,dp[k][i][j-1])

    print(max(dp[0][R-1][C-1],dp[1][R-1][C-1],dp[2][R-1][C-1],dp[3][R-1][C-1]))

if __name__ == "__main__":
    main()
