# -*- coding: utf-8 -*-



R,C,K = list(map(int, input().split()))



items = [[0 for _ in range(C+1)] for _ in range(R+1)]

for i in range(K):

  r,c,v = list(map(int, input().split()))

  items[r][c] = v



DP_prev = [0 for _ in range(C+1)]

for r in range(1,R+1):

  DP1 = [0 for _ in range(C+1)]

  DP2 = [0 for _ in range(C+1)]

  DP3 = [0 for _ in range(C+1)]

  for c in range(1,C+1):

    item = items[r][c]

    DP1[c] = max(DP_prev[c]+item,DP1[c-1])

    DP2[c] = max(DP1[c],DP2[c-1],DP1[c-1]+item)

    DP3[c] = max(DP2[c],DP3[c-1],DP2[c-1]+item)

  DP_prev = DP3

        

print((DP_prev[C]))
# -*- coding: utf-8 -*-



R,C,K = list(map(int, input().split()))



items = [[0 for _ in range(C+1)] for _ in range(R+1)]

for i in range(K):

  r,c,v = list(map(int, input().split()))

  items[r][c] = v



DP_prev = [0 for _ in range(C+1)]

DP1 = [0 for _ in range(C+1)]

DP2 = [0 for _ in range(C+1)]

DP3 = [0 for _ in range(C+1)]

for r in range(1,R+1):

  for c in range(1,C+1):

    item = items[r][c]

    DP1[c] = max(DP_prev[c]+item,DP1[c-1])

    DP2[c] = max(DP1[c],DP2[c-1],DP1[c-1]+item)

    DP3[c] = max(DP2[c],DP3[c-1],DP2[c-1]+item)

  DP_prev = DP3

        

print((DP_prev[C]))
# -*- coding: utf-8 -*-
R, C, K = list(map(int, input().split()))
items = [[0 for _ in range(C + 1)] for _ in range(R + 1)]
for i in range(K):
    r, c, v = list(map(int, input().split()))
    items[r][c] = v
DP_prev = [0 for _ in range(C + 1)]
for r in range(1, R + 1):
    DP1 = [0 for _ in range(C + 1)]
    DP2 = [0 for _ in range(C + 1)]
    DP3 = [0 for _ in range(C + 1)]
    for c in range(1, C + 1):
        item = items[r][c]
        DP1[c] = max(DP_prev[c] + item, DP1[c - 1])
        DP2[c] = max(DP1[c], DP2[c - 1], DP1[c - 1] + item)
        DP3[c] = max(DP2[c], DP3[c - 1], DP2[c - 1] + item)
    DP_prev = DP3
print((DP_prev[C]))

# -*- coding: utf-8 -*-
R, C, K = list(map(int, input().split()))
items = [[0 for _ in range(C + 1)] for _ in range(R + 1)]
for i in range(K):
    r, c, v = list(map(int, input().split()))
    items[r][c] = v
DP_prev = [0 for _ in range(C + 1)]
DP1 = [0 for _ in range(C + 1)]
DP2 = [0 for _ in range(C + 1)]
DP3 = [0 for _ in range(C + 1)]
for r in range(1, R + 1):
    for c in range(1, C + 1):
        item = items[r][c]
        DP1[c] = max(DP_prev[c] + item, DP1[c - 1])
        DP2[c] = max(DP1[c], DP2[c - 1], DP1[c - 1] + item)
        DP3[c] = max(DP2[c], DP3[c - 1], DP2[c - 1] + item)
    DP_prev = DP3
print((DP_prev[C]))

+DP1 = [0 for _ in range(C + 1)] +DP2 = [0 for _ in range(C + 1)] +DP3 = [0 for _ in range(C + 1)] -    DP1 = [0 for _ in range(C + 1)] -    DP2 = [0 for _ in range(C + 1)] -    DP3 = [0 for _ in range(C + 1)]