### BUGGY CODE ###

# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
#from itertools import product, accumulate, combinations, product
#import bisect
#import numpy as np
#from copy import deepcopy
#from collections import deque
#from decimal import Decimal

def appmax(dp, idxes1, val):
    i, j, k = idxes1
    dp[i][j][k] = max(dp[i][j][k], val)

INF = 1 << 63


def run():
    R,C,K = map(int, sysread().split())
    MAP = [[0] * (C+1) for _ in range(R+1)]
    for i in range(K):
        r, c, v = map(int, sysread().split())
        MAP[r][c] = v

    dp = [[[0] * 4 for _ in range(C+1)] for i in range(R+1)]

    for i in range(R+1):
        for j in range(C+1):
            for k in range(4):
                if i < R:
                    appmax(dp, (i+1, j, 0), dp[i][j][k])
                    if MAP[i+1][j]:
                        appmax(dp, (i+1, j, 1), dp[i][j][k] + MAP[i+1][j])
                if j < C:
                    appmax(dp, (i, j+1, k), dp[i][j][k])
                    if MAP[i][j+1] and k < 3:
                        appmax(dp, (i, j+1, k+1), dp[i][j][k] + MAP[i][j+1])
    #print(dp)
    #for m in MAP:
    #    print(m)
    print(max(dp[R][C]))

if __name__ == "__main__":
    run()

### FIXED CODE ###

# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
#from itertools import product, accumulate, combinations, product
import bisect
import numpy as np
#from copy import deepcopy
#from collections import deque
#from decimal import Decimal


from numba import jit

@jit
def run_dp(MAP, dp, Rs, Cs):
    for i in range(1, len(Rs)+1):
        for j in range(1, len(Cs)+1):
            for k in range(4):
                dp[i][j][0] = max(dp[i][j][0], dp[i-1][j][k])
                if MAP[i][j]:
                    dp[i][j][1] = max(dp[i][j][1], dp[i-1][j][k]+MAP[i][j])

                dp[i][j][k] = max(dp[i][j][k], dp[i][j-1][k])
                if MAP[i][j] and k < 3:
                    dp[i][j][k+1] = max(dp[i][j][k+1], dp[i][j-1][k] + MAP[i][j])
    return dp

def run():
    R,C,K = map(int, sysread().split())
    Rs = set()
    Cs = set()
    vals = []
    for i in range(K):
        r, c, v = map(int, sysread().split())
        vals.append((r, c, v))
        Rs.add(r)
        Cs.add(c)
    #Rs = sorted(list(Rs))
    Rs = np.array(sorted(list(Rs)))
    #Cs = sorted(list(Cs))
    Cs = np.array(sorted(list(Cs)))
    r_idx = {r:i+1 for i, r in enumerate(Rs)}
    c_idx = {c:i+1 for i, c in enumerate(Cs)}
    #MAP = [[0] * (len(Cs)+1) for _ in range(len(Rs)+1)]
    MAP = np.zeros((len(Rs)+1, len(Cs)+1), dtype= np.int64)
    for r,c,v in vals:
        rn = r_idx[r]
        cn = c_idx[c]
        MAP[rn][cn] = v

    #dp = [[[0] * 4 for _ in range(len(Cs)+1)] for i in range(len(Rs)+1)]
    dp = np.zeros((len(Rs)+1, len(Cs)+1, 4), dtype= np.int64)

    run_dp(MAP, dp, Rs, Cs)

    #print(dp)
    #for m in MAP:
    #   print(m)
    dp = run_dp(MAP, dp, Rs, Cs)

    print(max(dp[len(Rs)][len(Cs)]))

if __name__ == "__main__":
    run()