import sys
import math
import copy
import random
import itertools
from heapq import heappush, heappop, heapify
from functools import cmp_to_key
from bisect import bisect_left, bisect_right
from collections import defaultdict, deque, Counter
sys.setrecursionlimit(1000000)

# input aliases
input = sys.stdin.readline
getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]

INF = 10 ** 21
MOD = 10**9 + 7
divide = lambda x: pow(x, MOD-2, MOD)

def solve(n=None, s1=None, s2=None):
    r, c, k = getList()
    value = [[0] * (c + 1) for i in range(r)]

    for i in range(k):
        cr, cc, cv = getZList()
        cv += 1
        value[cr][cc + 1] = cv

    dp = [[[0] * (c + 1) for i in range(r)] for j in range(4)]
    # print(value)
    # print("")
    for y in range(r):
        for x in range(1, c+1):
            curv = value[y][x]
            if y > 0:
                dp[0][y][x] = max(
                    dp[0][y-1][x],
                    dp[1][y-1][x],
                    dp[2][y-1][x],
                    dp[3][y-1][x]
                )
                dp[1][y][x] = max(
                    dp[0][y - 1][x] + curv,
                    dp[1][y - 1][x] + curv,
                    dp[2][y - 1][x] + curv,
                    dp[3][y - 1][x] + curv
                )
            if curv == 0:
                for z in range(4):
                    dp[z][y][x] = max(dp[z][y][x], dp[z][y][x-1])

            else:
                dp[0][y][x] = max(dp[0][y][x], dp[0][y][x-1])
                dp[1][y][x] = max(dp[1][y][x], dp[1][y][x-1], dp[0][y][x-1] + curv)
                dp[2][y][x] = max(dp[2][y][x], dp[2][y][x-1], dp[1][y][x - 1] + curv)
                dp[3][y][x] = max(dp[3][y][x], dp[3][y][x-1], dp[2][y][x - 1] + curv)

    # for dd in dp:
    #     print(dd)

    ans = 0
    for z in range(4):
        for y in range(r):
            for x in range(1, c+1):
                ans = max(ans, dp[z][y][x])

    print(ans)

def main():
    n = getN()
    for _ in range(n):
        solve()
    return


if __name__ == "__main__":
    # main()
    solve()
 import sys sys import math math import copy copy import random random import itertools itertools from heapq import heappush, heappop, heapify from functools import cmp_to_key from bisect import bisect_left, bisect_right from collections import defaultdict, deque, Counter sys.setrecursionlimit(1000000) sys.setrecursionlimit sys setrecursionlimit 1000000 input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline getS = lambda: input().strip() getS lambda: input().strip() input().strip() ().strip () input strip getN = lambda: int(input()) getN lambda: int(input()) int(input()) int input() input getList = lambda: list(map(int, input().split())) getList lambda: list(map(int, input().split())) list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split int(x) - 1 for x in input().split() for x in input().split() x input().split() ().split () input split for x in input().split() int(x) - 1 int(x) int x 1 getZList = lambda: [int(x) - 1 for x in input().split()] getZList lambda: [int(x) - 1 for x in input().split()] [int(x) - 1 for x in input().split()] INF = 10 ** 21 INF 10 ** 21 10 21 MOD = 10**9 + 7 MOD 10**9 + 7 10**9 10 9 7 divide = lambda x: pow(x, MOD-2, MOD) divide lambda x: pow(x, MOD-2, MOD) pow(x, MOD-2, MOD) pow x MOD-2 MOD 2 MOD x def solve(n=None, s1=None, s2=None):
    r, c, k = getList()
    value = [[0] * (c + 1) for i in range(r)]

    for i in range(k):
        cr, cc, cv = getZList()
        cv += 1
        value[cr][cc + 1] = cv

    dp = [[[0] * (c + 1) for i in range(r)] for j in range(4)]
    # print(value)
    # print("")
    for y in range(r):
        for x in range(1, c+1):
            curv = value[y][x]
            if y > 0:
                dp[0][y][x] = max(
                    dp[0][y-1][x],
                    dp[1][y-1][x],
                    dp[2][y-1][x],
                    dp[3][y-1][x]
                )
                dp[1][y][x] = max(
                    dp[0][y - 1][x] + curv,
                    dp[1][y - 1][x] + curv,
                    dp[2][y - 1][x] + curv,
                    dp[3][y - 1][x] + curv
                )
            if curv == 0:
                for z in range(4):
                    dp[z][y][x] = max(dp[z][y][x], dp[z][y][x-1])

            else:
                dp[0][y][x] = max(dp[0][y][x], dp[0][y][x-1])
                dp[1][y][x] = max(dp[1][y][x], dp[1][y][x-1], dp[0][y][x-1] + curv)
                dp[2][y][x] = max(dp[2][y][x], dp[2][y][x-1], dp[1][y][x - 1] + curv)
                dp[3][y][x] = max(dp[3][y][x], dp[3][y][x-1], dp[2][y][x - 1] + curv)

    # for dd in dp:
    #     print(dd)

    ans = 0
    for z in range(4):
        for y in range(r):
            for x in range(1, c+1):
                ans = max(ans, dp[z][y][x])

    print(ans) solve r, c, k = getList() r getList() getList c k [0] * (c + 1) for i in range(r) for i in range(r) i range(r) range r for i in range(r) [0] * (c + 1) [0] 0 c + 1 c 1 value = [[0] * (c + 1) for i in range(r)] value [[0] * (c + 1) for i in range(r)] for i in range(k):
        cr, cc, cv = getZList()
        cv += 1
        value[cr][cc + 1] = cv

     i range(k) range k cr, cc, cv = getZList() cr getZList() getZList cc cv cv += 1 cv 1 value[cr][cc + 1] = cv value[cr][cc + 1] [cr] value cr cc + 1 cc 1 cv [[0] * (c + 1) for i in range(r)] for j in range(4) for j in range(4) j range(4) range 4 for j in range(4) [[0] * (c + 1) for i in range(r)] dp = [[[0] * (c + 1) for i in range(r)] for j in range(4)] dp [[[0] * (c + 1) for i in range(r)] for j in range(4)] for y in range(r):
        for x in range(1, c+1):
            curv = value[y][x]
            if y > 0:
                dp[0][y][x] = max(
                    dp[0][y-1][x],
                    dp[1][y-1][x],
                    dp[2][y-1][x],
                    dp[3][y-1][x]
                )
                dp[1][y][x] = max(
                    dp[0][y - 1][x] + curv,
                    dp[1][y - 1][x] + curv,
                    dp[2][y - 1][x] + curv,
                    dp[3][y - 1][x] + curv
                )
            if curv == 0:
                for z in range(4):
                    dp[z][y][x] = max(dp[z][y][x], dp[z][y][x-1])

            else:
                dp[0][y][x] = max(dp[0][y][x], dp[0][y][x-1])
                dp[1][y][x] = max(dp[1][y][x], dp[1][y][x-1], dp[0][y][x-1] + curv)
                dp[2][y][x] = max(dp[2][y][x], dp[2][y][x-1], dp[1][y][x - 1] + curv)
                dp[3][y][x] = max(dp[3][y][x], dp[3][y][x-1], dp[2][y][x - 1] + curv)

    # for dd in dp:
    #     print(dd)

     y range(r) range r for x in range(1, c+1):
            curv = value[y][x]
            if y > 0:
                dp[0][y][x] = max(
                    dp[0][y-1][x],
                    dp[1][y-1][x],
                    dp[2][y-1][x],
                    dp[3][y-1][x]
                )
                dp[1][y][x] = max(
                    dp[0][y - 1][x] + curv,
                    dp[1][y - 1][x] + curv,
                    dp[2][y - 1][x] + curv,
                    dp[3][y - 1][x] + curv
                )
            if curv == 0:
                for z in range(4):
                    dp[z][y][x] = max(dp[z][y][x], dp[z][y][x-1])

            else:
                dp[0][y][x] = max(dp[0][y][x], dp[0][y][x-1])
                dp[1][y][x] = max(dp[1][y][x], dp[1][y][x-1], dp[0][y][x-1] + curv)
                dp[2][y][x] = max(dp[2][y][x], dp[2][y][x-1], dp[1][y][x - 1] + curv)
                dp[3][y][x] = max(dp[3][y][x], dp[3][y][x-1], dp[2][y][x - 1] + curv)

    # for dd in dp:
    #     print(dd)

     x range(1, c+1) range 1 c+1 c 1 curv = value[y][x] curv value[y][x] [y] value y x if y > 0:
                dp[0][y][x] = max(
                    dp[0][y-1][x],
                    dp[1][y-1][x],
                    dp[2][y-1][x],
                    dp[3][y-1][x]
                )
                dp[1][y][x] = max(
                    dp[0][y - 1][x] + curv,
                    dp[1][y - 1][x] + curv,
                    dp[2][y - 1][x] + curv,
                    dp[3][y - 1][x] + curv
                )
             y > 0 y 0 dp[0][y][x] = max(
                    dp[0][y-1][x],
                    dp[1][y-1][x],
                    dp[2][y-1][x],
                    dp[3][y-1][x]
                ) dp[0][y][x] [y] [0] dp 0 y x max(
                    dp[0][y-1][x],
                    dp[1][y-1][x],
                    dp[2][y-1][x],
                    dp[3][y-1][x]
                ) max dp[0][y-1][x] [y-1] [0] dp 0 y-1 y 1 x dp[1][y-1][x] [y-1] [1] dp 1 y-1 y 1 x dp[2][y-1][x] [y-1] [2] dp 2 y-1 y 1 x dp[3][y-1][x] [y-1] [3] dp 3 y-1 y 1 x dp[1][y][x] = max(
                    dp[0][y - 1][x] + curv,
                    dp[1][y - 1][x] + curv,
                    dp[2][y - 1][x] + curv,
                    dp[3][y - 1][x] + curv
                ) dp[1][y][x] [y] [1] dp 1 y x max(
                    dp[0][y - 1][x] + curv,
                    dp[1][y - 1][x] + curv,
                    dp[2][y - 1][x] + curv,
                    dp[3][y - 1][x] + curv
                ) max dp[0][y - 1][x] + curv dp[0][y - 1][x] [y - 1] [0] dp 0 y - 1 y 1 x curv dp[1][y - 1][x] + curv dp[1][y - 1][x] [y - 1] [1] dp 1 y - 1 y 1 x curv dp[2][y - 1][x] + curv dp[2][y - 1][x] [y - 1] [2] dp 2 y - 1 y 1 x curv dp[3][y - 1][x] + curv dp[3][y - 1][x] [y - 1] [3] dp 3 y - 1 y 1 x curv if curv == 0:
                for z in range(4):
                    dp[z][y][x] = max(dp[z][y][x], dp[z][y][x-1])

            else:
                dp[0][y][x] = max(dp[0][y][x], dp[0][y][x-1])
                dp[1][y][x] = max(dp[1][y][x], dp[1][y][x-1], dp[0][y][x-1] + curv)
                dp[2][y][x] = max(dp[2][y][x], dp[2][y][x-1], dp[1][y][x - 1] + curv)
                dp[3][y][x] = max(dp[3][y][x], dp[3][y][x-1], dp[2][y][x - 1] + curv)

    # for dd in dp:
    #     print(dd)

     curv == 0 curv 0 for z in range(4):
                    dp[z][y][x] = max(dp[z][y][x], dp[z][y][x-1])

             z range(4) range 4 dp[z][y][x] = max(dp[z][y][x], dp[z][y][x-1]) dp[z][y][x] [y] [z] dp z y x max(dp[z][y][x], dp[z][y][x-1]) max dp[z][y][x] [y] [z] dp z y x dp[z][y][x-1] [y] [z] dp z y x-1 x 1 dp[0][y][x] = max(dp[0][y][x], dp[0][y][x-1]) dp[0][y][x] [y] [0] dp 0 y x max(dp[0][y][x], dp[0][y][x-1]) max dp[0][y][x] [y] [0] dp 0 y x dp[0][y][x-1] [y] [0] dp 0 y x-1 x 1 dp[1][y][x] = max(dp[1][y][x], dp[1][y][x-1], dp[0][y][x-1] + curv) dp[1][y][x] [y] [1] dp 1 y x max(dp[1][y][x], dp[1][y][x-1], dp[0][y][x-1] + curv) max dp[1][y][x] [y] [1] dp 1 y x dp[1][y][x-1] [y] [1] dp 1 y x-1 x 1 dp[0][y][x-1] + curv dp[0][y][x-1] [y] [0] dp 0 y x-1 x 1 curv dp[2][y][x] = max(dp[2][y][x], dp[2][y][x-1], dp[1][y][x - 1] + curv) dp[2][y][x] [y] [2] dp 2 y x max(dp[2][y][x], dp[2][y][x-1], dp[1][y][x - 1] + curv) max dp[2][y][x] [y] [2] dp 2 y x dp[2][y][x-1] [y] [2] dp 2 y x-1 x 1 dp[1][y][x - 1] + curv dp[1][y][x - 1] [y] [1] dp 1 y x - 1 x 1 curv dp[3][y][x] = max(dp[3][y][x], dp[3][y][x-1], dp[2][y][x - 1] + curv) dp[3][y][x] [y] [3] dp 3 y x max(dp[3][y][x], dp[3][y][x-1], dp[2][y][x - 1] + curv) max dp[3][y][x] [y] [3] dp 3 y x dp[3][y][x-1] [y] [3] dp 3 y x-1 x 1 dp[2][y][x - 1] + curv dp[2][y][x - 1] [y] [2] dp 2 y x - 1 x 1 curv ans = 0 ans 0 for z in range(4):
        for y in range(r):
            for x in range(1, c+1):
                ans = max(ans, dp[z][y][x])

     z range(4) range 4 for y in range(r):
            for x in range(1, c+1):
                ans = max(ans, dp[z][y][x])

     y range(r) range r for x in range(1, c+1):
                ans = max(ans, dp[z][y][x])

     x range(1, c+1) range 1 c+1 c 1 ans = max(ans, dp[z][y][x]) ans max(ans, dp[z][y][x]) max ans dp[z][y][x] [y] [z] dp z y x print(ans) print ans n=None n None s1=None s1 None s2=None s2 None def main():
    n = getN()
    for _ in range(n):
        solve()
    return main n = getN() n getN() getN for _ in range(n):
        solve()
     _ range(n) range n solve() solve return if __name__ == "__main__":
    # main()
    solve() __name__ == "__main__" __name__ "__main__" solve() solve getN = lambda: int(input()) lambda: int(input()) getN def solve(n=None, s1=None, s2=None):
    r, c, k = getList()
    value = [[0] * (c + 1) for i in range(r)]

    for i in range(k):
        cr, cc, cv = getZList()
        cv += 1
        value[cr][cc + 1] = cv

    dp = [[[0] * (c + 1) for i in range(r)] for j in range(4)]
    # print(value)
    # print("")
    for y in range(r):
        for x in range(1, c+1):
            curv = value[y][x]
            if y > 0:
                dp[0][y][x] = max(
                    dp[0][y-1][x],
                    dp[1][y-1][x],
                    dp[2][y-1][x],
                    dp[3][y-1][x]
                )
                dp[1][y][x] = max(
                    dp[0][y - 1][x] + curv,
                    dp[1][y - 1][x] + curv,
                    dp[2][y - 1][x] + curv,
                    dp[3][y - 1][x] + curv
                )
            if curv == 0:
                for z in range(4):
                    dp[z][y][x] = max(dp[z][y][x], dp[z][y][x-1])

            else:
                dp[0][y][x] = max(dp[0][y][x], dp[0][y][x-1])
                dp[1][y][x] = max(dp[1][y][x], dp[1][y][x-1], dp[0][y][x-1] + curv)
                dp[2][y][x] = max(dp[2][y][x], dp[2][y][x-1], dp[1][y][x - 1] + curv)
                dp[3][y][x] = max(dp[3][y][x], dp[3][y][x-1], dp[2][y][x - 1] + curv)

    # for dd in dp:
    #     print(dd)

    ans = 0
    for z in range(4):
        for y in range(r):
            for x in range(1, c+1):
                ans = max(ans, dp[z][y][x])

    print(ans) def solve(n=None, s1=None, s2=None):
    r, c, k = getList()
    value = [[0] * (c + 1) for i in range(r)]

    for i in range(k):
        cr, cc, cv = getZList()
        cv += 1
        value[cr][cc + 1] = cv

    dp = [[[0] * (c + 1) for i in range(r)] for j in range(4)]
    # print(value)
    # print("")
    for y in range(r):
        for x in range(1, c+1):
            curv = value[y][x]
            if y > 0:
                dp[0][y][x] = max(
                    dp[0][y-1][x],
                    dp[1][y-1][x],
                    dp[2][y-1][x],
                    dp[3][y-1][x]
                )
                dp[1][y][x] = max(
                    dp[0][y - 1][x] + curv,
                    dp[1][y - 1][x] + curv,
                    dp[2][y - 1][x] + curv,
                    dp[3][y - 1][x] + curv
                )
            if curv == 0:
                for z in range(4):
                    dp[z][y][x] = max(dp[z][y][x], dp[z][y][x-1])

            else:
                dp[0][y][x] = max(dp[0][y][x], dp[0][y][x-1])
                dp[1][y][x] = max(dp[1][y][x], dp[1][y][x-1], dp[0][y][x-1] + curv)
                dp[2][y][x] = max(dp[2][y][x], dp[2][y][x-1], dp[1][y][x - 1] + curv)
                dp[3][y][x] = max(dp[3][y][x], dp[3][y][x-1], dp[2][y][x - 1] + curv)

    # for dd in dp:
    #     print(dd)

    ans = 0
    for z in range(4):
        for y in range(r):
            for x in range(1, c+1):
                ans = max(ans, dp[z][y][x])

    print(ans) solve INF = 10 ** 21 10 ** 21 INF input = sys.stdin.readline sys.stdin.readline input divide = lambda x: pow(x, MOD-2, MOD) lambda x: pow(x, MOD-2, MOD) divide getS = lambda: input().strip() lambda: input().strip() getS getZList = lambda: [int(x) - 1 for x in input().split()] lambda: [int(x) - 1 for x in input().split()] getZList MOD = 10**9 + 7 10**9 + 7 MOD def main():
    n = getN()
    for _ in range(n):
        solve()
    return def main():
    n = getN()
    for _ in range(n):
        solve()
    return main getList = lambda: list(map(int, input().split())) lambda: list(map(int, input().split())) getList
import sys
import math
import copy
import random
import itertools
from heapq import heappush, heappop, heapify
from functools import cmp_to_key
from bisect import bisect_left, bisect_right
from collections import defaultdict, deque, Counter
sys.setrecursionlimit(1000000)

# input aliases
input = sys.stdin.readline
getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]

INF = 10 ** 21
MOD = 10**9 + 7
divide = lambda x: pow(x, MOD-2, MOD)

def solve(n=None, s1=None, s2=None):
    r, c, k = getList()
    value = [[0] * (c + 1) for i in range(r)]

    for i in range(k):
        cr, cc, cv = getZList()
        cv += 1
        value[cr][cc + 1] = cv

    dp = [[[0] * (c + 1) for i in range(r)] for j in range(4)]
    # print(value)
    # print("")
    for y in range(r):
        for x in range(1, c+1):
            curv = value[y][x]
            if y > 0:
                dp[0][y][x] = max(
                    dp[0][y-1][x],
                    dp[1][y-1][x],
                    dp[2][y-1][x],
                    dp[3][y-1][x]
                )
                dp[1][y][x] = max(
                    dp[0][y - 1][x] + curv,
                    dp[1][y - 1][x] + curv,
                    dp[2][y - 1][x] + curv,
                    dp[3][y - 1][x] + curv
                )
            if curv == 0:
                for z in range(4):
                    dp[z][y][x] = max(dp[z][y][x], dp[z][y][x-1])

            else:
                dp[0][y][x] = max(dp[0][y][x], dp[0][y][x-1])
                dp[1][y][x] = max(dp[1][y][x], dp[1][y][x-1], dp[0][y][x-1] + curv)
                dp[2][y][x] = max(dp[2][y][x], dp[2][y][x-1], dp[1][y][x - 1] + curv)
                dp[3][y][x] = max(dp[3][y][x], dp[3][y][x-1], dp[2][y][x - 1] + curv)

    # for dd in dp:
    #     print(dd)

    ans = 0
    for z in range(4):
        for y in range(r):
            for x in range(1, c+1):
                ans = max(ans, dp[z][y][x])

    print(ans)

def main():
    n = getN()
    for _ in range(n):
        solve()
    return


if __name__ == "__main__":
    # main()
    solve()

