def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
from math import sqrt
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul, itemgetter
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

#############
# Main Code #
#############

R, C, K = getNM()
point = [[0] * C for i in range(R)]
for i in range(K):
    r, c, v = getNM()
    point[r - 1][c - 1] = v

# dp[j][n] j列目にn個まで取った時の最大値
# 蟻本で出てた、前と後のdpを取り替える作業をしないと盛大にTLEる
prev = [[0] * 4 for _ in range(C + 1)]

for i in range(R):
    next = [[0] * 4 for _ in range(C + 1)]
    for j in range(C):
        # ①取った時
        # n = 2, n = 1, n = 0と逆順にやらないとバグる
        # (n = 0の処理を先に行うと、n = 1の時「変更後の」n = 0で計算を行ってしまうため)
        # (つまりpoint[i][j]のアイテムを何回も取得するため）
        
        # ②より扱うjの数が小さくなるので先に処理する
        # (こちらは②でprev[j + 1][n]の計算をする時「変更後の」prev[j][n]で計算する必要があるため）
        for n in range(2, -1, -1):
            prev[j][n + 1] = max(prev[j][n + 1], prev[j][n] + point[i][j])

        # ②取らない時
        for n in range(4):
            prev[j + 1][n] = max(prev[j + 1][n], prev[j][n])

        # ③下段に降りた時
        next[j][0] = max(prev[j])

    # dpの取り替え
    prev = next

print(max(prev[C - 1])) def getN():
    return int(input()) getN return int(input()) int(input()) int input() input def getNM():
    return map(int, input().split()) getNM return map(int, input().split()) map(int, input().split()) map int input().split() ().split () input split def getList():
    return list(map(int, input().split())) getList return list(map(int, input().split())) list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split def getArray(intn):
    return [int(input()) for i in range(intn)] getArray int(input()) for i in range(intn) for i in range(intn) i range(intn) range intn for i in range(intn) int(input()) int input() input return [int(input()) for i in range(intn)] [int(input()) for i in range(intn)] intn intn 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 rand_N(ran1, ran2):
    return random.randint(ran1, ran2) rand_N return random.randint(ran1, ran2) random.randint(ran1, ran2) random.randint random randint ran1 ran2 ran1 ran1 ran2 ran2 def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)] rand_List random.randint(ran1, ran2) for i in range(rantime) for i in range(rantime) i range(rantime) range rantime for i in range(rantime) random.randint(ran1, ran2) random.randint random randint ran1 ran2 return [random.randint(ran1, ran2) for i in range(rantime)] [random.randint(ran1, ran2) for i in range(rantime)] ran1 ran1 ran2 ran2 rantime rantime def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns) rand_ints_nodup ns = [] ns [] while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
   len(ns) < rantime len(ns) len ns rantime n = random.randint(ran1, ran2) n random.randint(ran1, ran2) random.randint random randint ran1 ran2 if not n in ns:
      ns.append(n)
   not n in ns n in ns n ns ns.append(n) ns.append ns append n return sorted(ns) sorted(ns) sorted ns ran1 ran1 ran2 ran2 rantime rantime def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query) rand_query r_query = [] r_query [] while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
   len(r_query) < rantime len(r_query) len r_query rantime n_q = rand_ints_nodup(ran1, ran2, 2) n_q rand_ints_nodup(ran1, ran2, 2) rand_ints_nodup ran1 ran2 2 if not n_q in r_query:
      r_query.append(n_q)
   not n_q in r_query n_q in r_query n_q r_query r_query.append(n_q) r_query.append r_query append n_q return sorted(r_query) sorted(r_query) sorted r_query ran1 ran1 ran2 ran2 rantime rantime from collections import defaultdict, deque, Counter from sys import exit from decimal import * import heapq heapq from math import sqrt from fractions import gcd import random random import string string import copy copy from itertools import combinations, permutations, product from operator import mul, itemgetter from functools import reduce from bisect import bisect_left, bisect_right import sys sys sys.setrecursionlimit(1000000000) sys.setrecursionlimit sys setrecursionlimit 1000000000 mod = 10 ** 9 + 7 mod 10 ** 9 + 7 10 ** 9 10 9 7 R, C, K = getNM() R getNM() getNM C K [0] * C for i in range(R) for i in range(R) i range(R) range R for i in range(R) [0] * C [0] 0 C point = [[0] * C for i in range(R)] point [[0] * C for i in range(R)] for i in range(K):
    r, c, v = getNM()
    point[r - 1][c - 1] = v

# dp[j][n] j列目にn個まで取った時の最大値
# 蟻本で出てた、前と後のdpを取り替える作業をしないと盛大にTLEる i range(K) range K r, c, v = getNM() r getNM() getNM c v point[r - 1][c - 1] = v point[r - 1][c - 1] [r - 1] point r - 1 r 1 c - 1 c 1 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 prev = [[0] * 4 for _ in range(C + 1)] prev [[0] * 4 for _ in range(C + 1)] for i in range(R):
    next = [[0] * 4 for _ in range(C + 1)]
    for j in range(C):
        # ①取った時
        # n = 2, n = 1, n = 0と逆順にやらないとバグる
        # (n = 0の処理を先に行うと、n = 1の時「変更後の」n = 0で計算を行ってしまうため)
        # (つまりpoint[i][j]のアイテムを何回も取得するため）
        
        # ②より扱うjの数が小さくなるので先に処理する
        # (こちらは②でprev[j + 1][n]の計算をする時「変更後の」prev[j][n]で計算する必要があるため）
        for n in range(2, -1, -1):
            prev[j][n + 1] = max(prev[j][n + 1], prev[j][n] + point[i][j])

        # ②取らない時
        for n in range(4):
            prev[j + 1][n] = max(prev[j + 1][n], prev[j][n])

        # ③下段に降りた時
        next[j][0] = max(prev[j])

    # dpの取り替え
    prev = next 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 next = [[0] * 4 for _ in range(C + 1)] next [[0] * 4 for _ in range(C + 1)] for j in range(C):
        # ①取った時
        # n = 2, n = 1, n = 0と逆順にやらないとバグる
        # (n = 0の処理を先に行うと、n = 1の時「変更後の」n = 0で計算を行ってしまうため)
        # (つまりpoint[i][j]のアイテムを何回も取得するため）
        
        # ②より扱うjの数が小さくなるので先に処理する
        # (こちらは②でprev[j + 1][n]の計算をする時「変更後の」prev[j][n]で計算する必要があるため）
        for n in range(2, -1, -1):
            prev[j][n + 1] = max(prev[j][n + 1], prev[j][n] + point[i][j])

        # ②取らない時
        for n in range(4):
            prev[j + 1][n] = max(prev[j + 1][n], prev[j][n])

        # ③下段に降りた時
        next[j][0] = max(prev[j])

    # dpの取り替え
     j range(C) range C for n in range(2, -1, -1):
            prev[j][n + 1] = max(prev[j][n + 1], prev[j][n] + point[i][j])

        # ②取らない時
         n range(2, -1, -1) range 2 -1 -1 prev[j][n + 1] = max(prev[j][n + 1], prev[j][n] + point[i][j]) prev[j][n + 1] [j] prev j n + 1 n 1 max(prev[j][n + 1], prev[j][n] + point[i][j]) max prev[j][n + 1] [j] prev j n + 1 n 1 prev[j][n] + point[i][j] prev[j][n] [j] prev j n point[i][j] [i] point i j for n in range(4):
            prev[j + 1][n] = max(prev[j + 1][n], prev[j][n])

        # ③下段に降りた時
         n range(4) range 4 prev[j + 1][n] = max(prev[j + 1][n], prev[j][n]) prev[j + 1][n] [j + 1] prev j + 1 j 1 n max(prev[j + 1][n], prev[j][n]) max prev[j + 1][n] [j + 1] prev j + 1 j 1 n prev[j][n] [j] prev j n next[j][0] = max(prev[j]) next[j][0] [j] next j 0 max(prev[j]) max prev[j] prev j prev = next prev next print(max(prev[C - 1])) print max(prev[C - 1]) max prev[C - 1] prev C - 1 C 1 def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns) def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns) rand_ints_nodup point = [[0] * C for i in range(R)] [[0] * C for i in range(R)] point next = [[0] * 4 for _ in range(C + 1)] [[0] * 4 for _ in range(C + 1)] next def getArray(intn):
    return [int(input()) for i in range(intn)] def getArray(intn):
    return [int(input()) for i in range(intn)] getArray def getList():
    return list(map(int, input().split())) def getList():
    return list(map(int, input().split())) getList v = getNM() getNM() v prev = [[0] * 4 for _ in range(C + 1)] [[0] * 4 for _ in range(C + 1)] prev C, K = getNM() getNM() C K = getNM() getNM() K R, C, K = getNM() getNM() R c, v = getNM() getNM() c def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query) def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query) rand_query mod = 10 ** 9 + 7 10 ** 9 + 7 mod prev = next next prev def getN():
    return int(input()) def getN():
    return int(input()) getN def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)] def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)] rand_List def getNM():
    return map(int, input().split()) def getNM():
    return map(int, input().split()) getNM r, c, v = getNM() getNM() r def input():
    return sys.stdin.readline().rstrip() def input():
    return sys.stdin.readline().rstrip() input def rand_N(ran1, ran2):
    return random.randint(ran1, ran2) def rand_N(ran1, ran2):
    return random.randint(ran1, ran2) rand_N
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
from math import sqrt
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul, itemgetter
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

#############
# Main Code #
#############

R, C, K = getNM()
point = [[0] * C for i in range(R)]
for i in range(K):
    r, c, v = getNM()
    point[r - 1][c - 1] = v

# dp[j][n] j列目にn個まで取った時の最大値
# 蟻本で出てた、前と後のdpを取り替える作業をしないと盛大にTLEる
prev = [[0] * 4 for _ in range(C + 1)]

for i in range(R):
    next = [[0] * 4 for _ in range(C + 1)]
    for j in range(C):
        # ①取った時
        # n = 2, n = 1, n = 0と逆順にやらないとバグる
        # (n = 0の処理を先に行うと、n = 1の時「変更後の」n = 0で計算を行ってしまうため)
        # (つまりpoint[i][j]のアイテムを何回も取得するため）
        
        # ②より扱うjの数が小さくなるので先に処理する
        # (こちらは②でprev[j + 1][n]の計算をする時「変更後の」prev[j][n]で計算する必要があるため）
        for n in range(2, -1, -1):
            prev[j][n + 1] = max(prev[j][n + 1], prev[j][n] + point[i][j])

        # ②取らない時
        for n in range(4):
            prev[j + 1][n] = max(prev[j + 1][n], prev[j][n])

        # ③下段に降りた時
        next[j][0] = max(prev[j])

    # dpの取り替え
    prev = next

print(max(prev[C - 1]))