import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def solve():
    dp0 = [0] * (w + 1)
    dp1 = [0] * (w + 1)
    dp2 = [0] * (w + 1)
    dp3 = [0] * (w + 1)
    for i in range(h):
        for j in range(w):
            v = vv[i * w + j]
            if v:
                dp3[j] = max(dp3[j], dp2[j] + v)
                dp2[j] = max(dp2[j], dp1[j] + v)
                dp1[j] = max(dp1[j], dp0[j] + v)
            dp3[j + 1] = max(dp3[j + 1], dp3[j])
            dp2[j + 1] = max(dp2[j + 1], dp2[j])
            dp1[j + 1] = max(dp1[j + 1], dp1[j])
            dp0[j] = max(dp1[j], dp2[j], dp3[j])
    print(dp0[-2])

h, w, k = MI()
vv = [0] * h * w
for _ in range(k):
    i, j, v = MI()
    i, j = i - 1, j - 1
    vv[i * w + j] = v
solve() import sys sys sys.setrecursionlimit(10 ** 6) sys.setrecursionlimit sys setrecursionlimit 10 ** 6 10 6 int1 = lambda x: int(x) - 1 int1 lambda x: int(x) - 1 int(x) - 1 int(x) int x 1 x p2D = lambda x: print(*x, sep="\n") p2D lambda x: print(*x, sep="\n") print(*x, sep="\n") print *x x sep="\n" sep "\n" x def II(): return int(sys.stdin.readline()) II def MI(): return map(int, sys.stdin.readline().split()) MI def LI(): return list(map(int, sys.stdin.readline().split())) LI LI() for _ in range(rows_number) for _ in range(rows_number) _ range(rows_number) range rows_number for _ in range(rows_number) LI() LI def LLI(rows_number): return [LI() for _ in range(rows_number)] LLI rows_number rows_number def SI(): return sys.stdin.readline()[:-1] SI def solve():
    dp0 = [0] * (w + 1)
    dp1 = [0] * (w + 1)
    dp2 = [0] * (w + 1)
    dp3 = [0] * (w + 1)
    for i in range(h):
        for j in range(w):
            v = vv[i * w + j]
            if v:
                dp3[j] = max(dp3[j], dp2[j] + v)
                dp2[j] = max(dp2[j], dp1[j] + v)
                dp1[j] = max(dp1[j], dp0[j] + v)
            dp3[j + 1] = max(dp3[j + 1], dp3[j])
            dp2[j + 1] = max(dp2[j + 1], dp2[j])
            dp1[j + 1] = max(dp1[j + 1], dp1[j])
            dp0[j] = max(dp1[j], dp2[j], dp3[j])
    print(dp0[-2]) solve dp0 = [0] * (w + 1) dp0 [0] * (w + 1) [0] 0 w + 1 w 1 dp1 = [0] * (w + 1) dp1 [0] * (w + 1) [0] 0 w + 1 w 1 dp2 = [0] * (w + 1) dp2 [0] * (w + 1) [0] 0 w + 1 w 1 dp3 = [0] * (w + 1) dp3 [0] * (w + 1) [0] 0 w + 1 w 1 for i in range(h):
        for j in range(w):
            v = vv[i * w + j]
            if v:
                dp3[j] = max(dp3[j], dp2[j] + v)
                dp2[j] = max(dp2[j], dp1[j] + v)
                dp1[j] = max(dp1[j], dp0[j] + v)
            dp3[j + 1] = max(dp3[j + 1], dp3[j])
            dp2[j + 1] = max(dp2[j + 1], dp2[j])
            dp1[j + 1] = max(dp1[j + 1], dp1[j])
            dp0[j] = max(dp1[j], dp2[j], dp3[j])
     i range(h) range h for j in range(w):
            v = vv[i * w + j]
            if v:
                dp3[j] = max(dp3[j], dp2[j] + v)
                dp2[j] = max(dp2[j], dp1[j] + v)
                dp1[j] = max(dp1[j], dp0[j] + v)
            dp3[j + 1] = max(dp3[j + 1], dp3[j])
            dp2[j + 1] = max(dp2[j + 1], dp2[j])
            dp1[j + 1] = max(dp1[j + 1], dp1[j])
            dp0[j] = max(dp1[j], dp2[j], dp3[j])
     j range(w) range w v = vv[i * w + j] v vv[i * w + j] vv i * w + j i * w i w j if v:
                dp3[j] = max(dp3[j], dp2[j] + v)
                dp2[j] = max(dp2[j], dp1[j] + v)
                dp1[j] = max(dp1[j], dp0[j] + v)
             v dp3[j] = max(dp3[j], dp2[j] + v) dp3[j] dp3 j max(dp3[j], dp2[j] + v) max dp3[j] dp3 j dp2[j] + v dp2[j] dp2 j v dp2[j] = max(dp2[j], dp1[j] + v) dp2[j] dp2 j max(dp2[j], dp1[j] + v) max dp2[j] dp2 j dp1[j] + v dp1[j] dp1 j v dp1[j] = max(dp1[j], dp0[j] + v) dp1[j] dp1 j max(dp1[j], dp0[j] + v) max dp1[j] dp1 j dp0[j] + v dp0[j] dp0 j v dp3[j + 1] = max(dp3[j + 1], dp3[j]) dp3[j + 1] dp3 j + 1 j 1 max(dp3[j + 1], dp3[j]) max dp3[j + 1] dp3 j + 1 j 1 dp3[j] dp3 j dp2[j + 1] = max(dp2[j + 1], dp2[j]) dp2[j + 1] dp2 j + 1 j 1 max(dp2[j + 1], dp2[j]) max dp2[j + 1] dp2 j + 1 j 1 dp2[j] dp2 j dp1[j + 1] = max(dp1[j + 1], dp1[j]) dp1[j + 1] dp1 j + 1 j 1 max(dp1[j + 1], dp1[j]) max dp1[j + 1] dp1 j + 1 j 1 dp1[j] dp1 j dp0[j] = max(dp1[j], dp2[j], dp3[j]) dp0[j] dp0 j max(dp1[j], dp2[j], dp3[j]) max dp1[j] dp1 j dp2[j] dp2 j dp3[j] dp3 j print(dp0[-2]) print dp0[-2] dp0 -2 h, w, k = MI() h MI() MI w k vv = [0] * h * w vv [0] * h * w [0] * h [0] 0 h w for _ in range(k):
    i, j, v = MI()
    i, j = i - 1, j - 1
    vv[i * w + j] = v _ range(k) range k i, j, v = MI() i MI() MI j v i, j = i - 1, j - 1 i i - 1 i 1 j j - 1 j 1 vv[i * w + j] = v vv[i * w + j] vv i * w + j i * w i w j v solve() solve h, w, k = MI() MI() h def solve():
    dp0 = [0] * (w + 1)
    dp1 = [0] * (w + 1)
    dp2 = [0] * (w + 1)
    dp3 = [0] * (w + 1)
    for i in range(h):
        for j in range(w):
            v = vv[i * w + j]
            if v:
                dp3[j] = max(dp3[j], dp2[j] + v)
                dp2[j] = max(dp2[j], dp1[j] + v)
                dp1[j] = max(dp1[j], dp0[j] + v)
            dp3[j + 1] = max(dp3[j + 1], dp3[j])
            dp2[j + 1] = max(dp2[j + 1], dp2[j])
            dp1[j + 1] = max(dp1[j + 1], dp1[j])
            dp0[j] = max(dp1[j], dp2[j], dp3[j])
    print(dp0[-2]) def solve():
    dp0 = [0] * (w + 1)
    dp1 = [0] * (w + 1)
    dp2 = [0] * (w + 1)
    dp3 = [0] * (w + 1)
    for i in range(h):
        for j in range(w):
            v = vv[i * w + j]
            if v:
                dp3[j] = max(dp3[j], dp2[j] + v)
                dp2[j] = max(dp2[j], dp1[j] + v)
                dp1[j] = max(dp1[j], dp0[j] + v)
            dp3[j + 1] = max(dp3[j + 1], dp3[j])
            dp2[j + 1] = max(dp2[j + 1], dp2[j])
            dp1[j + 1] = max(dp1[j + 1], dp1[j])
            dp0[j] = max(dp1[j], dp2[j], dp3[j])
    print(dp0[-2]) solve int1 = lambda x: int(x) - 1 lambda x: int(x) - 1 int1 def SI(): return sys.stdin.readline()[:-1] def SI(): return sys.stdin.readline()[:-1] SI k = MI() MI() k j, v = MI() MI() j i, j = i - 1, j - 1 i - 1 i j = i - 1, j - 1 j - 1 j def MI(): return map(int, sys.stdin.readline().split()) def MI(): return map(int, sys.stdin.readline().split()) MI i, j, v = MI() MI() i def LLI(rows_number): return [LI() for _ in range(rows_number)] def LLI(rows_number): return [LI() for _ in range(rows_number)] LLI w, k = MI() MI() w vv = [0] * h * w [0] * h * w vv v = MI() MI() v p2D = lambda x: print(*x, sep="\n") lambda x: print(*x, sep="\n") p2D def II(): return int(sys.stdin.readline()) def II(): return int(sys.stdin.readline()) II def LI(): return list(map(int, sys.stdin.readline().split())) def LI(): return list(map(int, sys.stdin.readline().split())) LI
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def solve():
    dp0 = [0] * (w + 1)
    dp1 = [0] * (w + 1)
    dp2 = [0] * (w + 1)
    dp3 = [0] * (w + 1)
    for i in range(h):
        for j in range(w):
            v = vv[i * w + j]
            if v:
                dp3[j] = max(dp3[j], dp2[j] + v)
                dp2[j] = max(dp2[j], dp1[j] + v)
                dp1[j] = max(dp1[j], dp0[j] + v)
            dp3[j + 1] = max(dp3[j + 1], dp3[j])
            dp2[j + 1] = max(dp2[j + 1], dp2[j])
            dp1[j + 1] = max(dp1[j + 1], dp1[j])
            dp0[j] = max(dp1[j], dp2[j], dp3[j])
    print(dp0[-2])

h, w, k = MI()
vv = [0] * h * w
for _ in range(k):
    i, j, v = MI()
    i, j = i - 1, j - 1
    vv[i * w + j] = v
solve()
