import sys
import math
import collections
import bisect
import itertools

# import numpy as np

sys.setrecursionlimit(10 ** 7)
INF = 10 ** 20
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline().rstrip())
ns = lambda: map(int, sys.stdin.readline().rstrip().split())
na = lambda: list(map(int, sys.stdin.readline().rstrip().split()))
na1 = lambda: list(map(lambda x: int(x) - 1, sys.stdin.readline().rstrip().split()))


# ===CODE===

def main():
    r, c, k = ns()

    mat = [[0 for _ in range(c + 1)] for __ in range(r + 1)]
    for _ in range(k):
        x, y, v = ns()
        x, y = x - 1, y - 1
        mat[x][y] = v

    dp = [[0] * 4 for _ in range(c + 1)]

    for i in range(r):
        ndp = [[0] * 4 for _ in range(c + 1)]
        for j in range(c):
            for n in range(2, -1, -1):
                dp[j][n + 1] = max(dp[j][n + 1], dp[j][n] + mat[i][j])

            ndp[j][0] = max(dp[j])
            for n in range(4):
                dp[j + 1][n] = max(dp[j + 1][n], dp[j][n])
        dp = ndp

    print(max(dp[c - 1]))


if __name__ == '__main__':
    main() import sys sys import math math import collections collections import bisect bisect import itertools itertools sys.setrecursionlimit(10 ** 7) sys.setrecursionlimit sys setrecursionlimit 10 ** 7 10 7 INF = 10 ** 20 INF 10 ** 20 10 20 MOD = 10 ** 9 + 7 MOD 10 ** 9 + 7 10 ** 9 10 9 7 ni = lambda: int(sys.stdin.readline().rstrip()) ni lambda: int(sys.stdin.readline().rstrip()) int(sys.stdin.readline().rstrip()) int sys.stdin.readline().rstrip() sys.stdin.readline().rstrip sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline rstrip ns = lambda: map(int, sys.stdin.readline().rstrip().split()) ns lambda: map(int, sys.stdin.readline().rstrip().split()) map(int, sys.stdin.readline().rstrip().split()) map int sys.stdin.readline().rstrip().split() sys.stdin.readline().rstrip().split sys.stdin.readline().rstrip() sys.stdin.readline().rstrip sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline rstrip split na = lambda: list(map(int, sys.stdin.readline().rstrip().split())) na lambda: list(map(int, sys.stdin.readline().rstrip().split())) list(map(int, sys.stdin.readline().rstrip().split())) list map(int, sys.stdin.readline().rstrip().split()) map int sys.stdin.readline().rstrip().split() sys.stdin.readline().rstrip().split sys.stdin.readline().rstrip() sys.stdin.readline().rstrip sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline rstrip split na1 = lambda: list(map(lambda x: int(x) - 1, sys.stdin.readline().rstrip().split())) na1 lambda: list(map(lambda x: int(x) - 1, sys.stdin.readline().rstrip().split())) list(map(lambda x: int(x) - 1, sys.stdin.readline().rstrip().split())) list map(lambda x: int(x) - 1, sys.stdin.readline().rstrip().split()) map lambda x: int(x) - 1 int(x) - 1 int(x) int x 1 x sys.stdin.readline().rstrip().split() sys.stdin.readline().rstrip().split sys.stdin.readline().rstrip() sys.stdin.readline().rstrip sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline rstrip split def main():
    r, c, k = ns()

    mat = [[0 for _ in range(c + 1)] for __ in range(r + 1)]
    for _ in range(k):
        x, y, v = ns()
        x, y = x - 1, y - 1
        mat[x][y] = v

    dp = [[0] * 4 for _ in range(c + 1)]

    for i in range(r):
        ndp = [[0] * 4 for _ in range(c + 1)]
        for j in range(c):
            for n in range(2, -1, -1):
                dp[j][n + 1] = max(dp[j][n + 1], dp[j][n] + mat[i][j])

            ndp[j][0] = max(dp[j])
            for n in range(4):
                dp[j + 1][n] = max(dp[j + 1][n], dp[j][n])
        dp = ndp

    print(max(dp[c - 1])) main r, c, k = ns() r ns() ns c k [0 for _ in range(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 for _ in range(c + 1)] mat = [[0 for _ in range(c + 1)] for __ in range(r + 1)] mat [[0 for _ in range(c + 1)] for __ in range(r + 1)] for _ in range(k):
        x, y, v = ns()
        x, y = x - 1, y - 1
        mat[x][y] = v

     _ range(k) range k x, y, v = ns() x ns() ns y v x, y = x - 1, y - 1 x x - 1 x 1 y y - 1 y 1 mat[x][y] = v mat[x][y] [x] mat x y v [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 i in range(r):
        ndp = [[0] * 4 for _ in range(c + 1)]
        for j in range(c):
            for n in range(2, -1, -1):
                dp[j][n + 1] = max(dp[j][n + 1], dp[j][n] + mat[i][j])

            ndp[j][0] = max(dp[j])
            for n in range(4):
                dp[j + 1][n] = max(dp[j + 1][n], dp[j][n])
        dp = ndp

     i range(r) range r [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 ndp = [[0] * 4 for _ in range(c + 1)] ndp [[0] * 4 for _ in range(c + 1)] for j in range(c):
            for n in range(2, -1, -1):
                dp[j][n + 1] = max(dp[j][n + 1], dp[j][n] + mat[i][j])

            ndp[j][0] = max(dp[j])
            for n in range(4):
                dp[j + 1][n] = max(dp[j + 1][n], dp[j][n])
         j range(c) range c for n in range(2, -1, -1):
                dp[j][n + 1] = max(dp[j][n + 1], dp[j][n] + mat[i][j])

             n range(2, -1, -1) range 2 -1 -1 dp[j][n + 1] = max(dp[j][n + 1], dp[j][n] + mat[i][j]) dp[j][n + 1] [j] dp j n + 1 n 1 max(dp[j][n + 1], dp[j][n] + mat[i][j]) max dp[j][n + 1] [j] dp j n + 1 n 1 dp[j][n] + mat[i][j] dp[j][n] [j] dp j n mat[i][j] [i] mat i j ndp[j][0] = max(dp[j]) ndp[j][0] [j] ndp j 0 max(dp[j]) max dp[j] dp j for n in range(4):
                dp[j + 1][n] = max(dp[j + 1][n], dp[j][n])
         n range(4) range 4 dp[j + 1][n] = max(dp[j + 1][n], dp[j][n]) dp[j + 1][n] [j + 1] dp j + 1 j 1 n max(dp[j + 1][n], dp[j][n]) max dp[j + 1][n] [j + 1] dp j + 1 j 1 n dp[j][n] [j] dp j n dp = ndp dp ndp print(max(dp[c - 1])) print max(dp[c - 1]) max dp[c - 1] dp c - 1 c 1 if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main na = lambda: list(map(int, sys.stdin.readline().rstrip().split())) lambda: list(map(int, sys.stdin.readline().rstrip().split())) na na1 = lambda: list(map(lambda x: int(x) - 1, sys.stdin.readline().rstrip().split())) lambda: list(map(lambda x: int(x) - 1, sys.stdin.readline().rstrip().split())) na1 def main():
    r, c, k = ns()

    mat = [[0 for _ in range(c + 1)] for __ in range(r + 1)]
    for _ in range(k):
        x, y, v = ns()
        x, y = x - 1, y - 1
        mat[x][y] = v

    dp = [[0] * 4 for _ in range(c + 1)]

    for i in range(r):
        ndp = [[0] * 4 for _ in range(c + 1)]
        for j in range(c):
            for n in range(2, -1, -1):
                dp[j][n + 1] = max(dp[j][n + 1], dp[j][n] + mat[i][j])

            ndp[j][0] = max(dp[j])
            for n in range(4):
                dp[j + 1][n] = max(dp[j + 1][n], dp[j][n])
        dp = ndp

    print(max(dp[c - 1])) def main():
    r, c, k = ns()

    mat = [[0 for _ in range(c + 1)] for __ in range(r + 1)]
    for _ in range(k):
        x, y, v = ns()
        x, y = x - 1, y - 1
        mat[x][y] = v

    dp = [[0] * 4 for _ in range(c + 1)]

    for i in range(r):
        ndp = [[0] * 4 for _ in range(c + 1)]
        for j in range(c):
            for n in range(2, -1, -1):
                dp[j][n + 1] = max(dp[j][n + 1], dp[j][n] + mat[i][j])

            ndp[j][0] = max(dp[j])
            for n in range(4):
                dp[j + 1][n] = max(dp[j + 1][n], dp[j][n])
        dp = ndp

    print(max(dp[c - 1])) main ns = lambda: map(int, sys.stdin.readline().rstrip().split()) lambda: map(int, sys.stdin.readline().rstrip().split()) ns INF = 10 ** 20 10 ** 20 INF ni = lambda: int(sys.stdin.readline().rstrip()) lambda: int(sys.stdin.readline().rstrip()) ni MOD = 10 ** 9 + 7 10 ** 9 + 7 MOD
import sys
import math
import collections
import bisect
import itertools

# import numpy as np

sys.setrecursionlimit(10 ** 7)
INF = 10 ** 20
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline().rstrip())
ns = lambda: map(int, sys.stdin.readline().rstrip().split())
na = lambda: list(map(int, sys.stdin.readline().rstrip().split()))
na1 = lambda: list(map(lambda x: int(x) - 1, sys.stdin.readline().rstrip().split()))


# ===CODE===

def main():
    r, c, k = ns()

    mat = [[0 for _ in range(c + 1)] for __ in range(r + 1)]
    for _ in range(k):
        x, y, v = ns()
        x, y = x - 1, y - 1
        mat[x][y] = v

    dp = [[0] * 4 for _ in range(c + 1)]

    for i in range(r):
        ndp = [[0] * 4 for _ in range(c + 1)]
        for j in range(c):
            for n in range(2, -1, -1):
                dp[j][n + 1] = max(dp[j][n + 1], dp[j][n] + mat[i][j])

            ndp[j][0] = max(dp[j])
            for n in range(4):
                dp[j + 1][n] = max(dp[j + 1][n], dp[j][n])
        dp = ndp

    print(max(dp[c - 1]))


if __name__ == '__main__':
    main()
