# Original solution
import sys
import math
from collections import defaultdict, deque
from copy import deepcopy
    
input = sys.stdin.readline
def RD(): return input().rstrip()
def F(): return float(input().rstrip())
def I(): return int(input().rstrip())
def MI(): return list(map(int, input().split()))
def MF(): return list(map(float,input().split()))
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float,input().split()))
def Init(H, W, num): return [[num for i in range(W)] for j in range(H)]
def end_of_loop():raise StopIteration
    
    
def main():
    R, C, K = MI()
    mylist = [[0 for i in range(C)] for j in range(R)]
    for i in range(K):
        a, b, c = MI()
        mylist[a-1][b-1] = c
    d = [[defaultdict(lambda:-float('inf')) for i in range(C)] for j in range(R)]
    for i in range(R):
        if i == 0:
            #初期化
            if mylist[0][0] != 0:
                d[0][0][0] = 0
                d[0][0][1] = mylist[0][0]
            else:
                d[0][0][0] = mylist[0][0]

            for j in range(1,C):
                if mylist[i][j] != 0:
                    d[i][j][0] = d[i][j-1][0]
                    for k in range(1,4):
                        d[i][j][k] = max(d[i][j-1][k], d[i][j-1][k-1]+mylist[i][j])
                else:
                    d[i][j] = d[i][j-1]
        else:
            #初期化
            if mylist[i][0] != 0:
                d[i][0][0] = max(d[i-1][0].values())
                d[i][0][1] = d[i][0][0]+mylist[i][0]
            else:
                d[i][0][0] = max(d[i-1][0].values())
            for j in range(1,C):
                if mylist[i][j] != 0:
                    #0個の場合
                    d[i][j][0] = max(d[i][j-1][0], max(d[i-1][j].values()))
                    #1個の場合
                    d[i][j][1] = max(d[i][j-1][1], d[i][j-1][0]+mylist[i][j], max(d[i-1][j].values())+mylist[i][j])
                    #2個の場合
                    d[i][j][2] = max(d[i][j-1][2], d[i][j-1][1]+mylist[i][j])
                    #3個の場合
                    d[i][j][3] = max(d[i][j-1][3], d[i][j-1][2]+mylist[i][j])
                else:
                    #0個の場合
                    d[i][j][0] = max(d[i][j-1][0], max(d[i-1][j].values()))
                    #1個以上の場合
                    for k in range(1,4):
                        d[i][j][k] = d[i][j-1][k]
    print((max(d[R-1][C-1].values())))

if __name__ == "__main__":
    main()

# Optimized solution
import sys
import math
from collections import defaultdict, deque
from copy import deepcopy
    
input = sys.stdin.readline
def RD(): return input().rstrip()
def F(): return float(input().rstrip())
def I(): return int(input().rstrip())
def MI(): return list(map(int, input().split()))
def MF(): return list(map(float,input().split()))
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float,input().split()))
def Init(H, W, num): return [[num for i in range(W)] for j in range(H)]
def end_of_loop():raise StopIteration
    
    
def main():
    R, C, K = MI()
    mylist = [[0 for i in range(C)] for j in range(R)]
    for i in range(K):
        a, b, c = MI()
        mylist[a-1][b-1] = c
    d = [[[0] * 4 for i in range(C)] for j in range(R)]
    for i in range(R):
        if i == 0:
            #初期化
            d[0][0][1] = mylist[0][0]
            for k in range(1,4):
                d[0][0][k] = max(d[0][0][k], d[0][0][k-1])
            for j in range(1,C):
                temp = mylist[i][j]
                if temp != 0:
                    d[i][j][0] = d[i][j-1][0]
                    for k in range(1,4):
                        d[i][j][k] = max(d[i][j][k], d[i][j-1][k], d[i][j-1][k-1]+temp, d[i][j][k-1])
                else:
                    d[i][j] = d[i][j-1]
        else:
            #初期化
            d[i][0][0] = d[i-1][0][3]
            temp = mylist[i][0]
            for k in range(1,4):
                d[i][0][k] = d[i][0][0]+temp
            for j in range(1,C):
                temp = mylist[i][j]
                add = d[i-1][j][3]
                #0の場合
                d[i][j][0] = max(d[i][j-1][0], add)
                if temp != 0:
                    #1個の場合
                    d[i][j][1] = max(d[i][j-1][1], d[i][j-1][0]+temp, add+temp)
                    #2個の場合
                    d[i][j][2] = max(d[i][j-1][2], d[i][j-1][1]+temp)
                    #3個の場合
                    d[i][j][3] = max(d[i][j-1][3], d[i][j-1][2]+temp)
                    for k in range(1,4):
                        d[i][j][k] = max(d[i][j][k], d[i][j][k-1])
                else:
                    #1個以上の場合
                    for k in range(1,4):
                        d[i][j][k] = max(d[i][j-1][k], d[i][j][k-1])
    print((d[R-1][C-1][3]))

if __name__ == "__main__":
    main()