import sys
input = sys.stdin.readline

def solve():
    INF = float('inf')

    def max2(x, y): return x if x >= y else y

    R, C, K = map(int, input().split())
    Vss = [[0]*(C+1) for _ in range(R+1)]
    for _ in range(K):
        r, c, v = map(int, input().split())
        Vss[r][c] = v

    dpMax = [0]*(C+1)
    for i in range(1, R+1):
        dp0 = [0]*(C+1)
        dp1 = [-INF]*(C+1)
        dp2 = [-INF]*(C+1)
        dp3 = [-INF]*(C+1)
        for j in range(1, C+1):
            V = Vss[i][j]
            dp0[j] = max2(dp0[j-1], dpMax[j])
            dp1[j] = max2(dp0[j] + V, dp1[j-1])
            dp2[j] = max2(dp1[j-1] + V, dp2[j-1])
            dp3[j] = max2(dp2[j-1] + V, dp3[j-1])
            dpMax[j] = max(dp0[j], dp1[j], dp2[j], dp3[j])

    ans = dpMax[C]
    print(ans)


solve() import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline def solve():
    INF = float('inf')

    def max2(x, y): return x if x >= y else y

    R, C, K = map(int, input().split())
    Vss = [[0]*(C+1) for _ in range(R+1)]
    for _ in range(K):
        r, c, v = map(int, input().split())
        Vss[r][c] = v

    dpMax = [0]*(C+1)
    for i in range(1, R+1):
        dp0 = [0]*(C+1)
        dp1 = [-INF]*(C+1)
        dp2 = [-INF]*(C+1)
        dp3 = [-INF]*(C+1)
        for j in range(1, C+1):
            V = Vss[i][j]
            dp0[j] = max2(dp0[j-1], dpMax[j])
            dp1[j] = max2(dp0[j] + V, dp1[j-1])
            dp2[j] = max2(dp1[j-1] + V, dp2[j-1])
            dp3[j] = max2(dp2[j-1] + V, dp3[j-1])
            dpMax[j] = max(dp0[j], dp1[j], dp2[j], dp3[j])

    ans = dpMax[C]
    print(ans) solve INF = float('inf') INF float('inf') float 'inf' def max2(x, y): return x if x >= y else y

     max2 x x y y R, C, K = map(int, input().split()) R map(int, input().split()) map int input().split() ().split () input split C K [0]*(C+1) for _ in range(R+1) for _ in range(R+1) _ range(R+1) range R+1 R 1 for _ in range(R+1) [0]*(C+1) [0] 0 C+1 C 1 Vss = [[0]*(C+1) for _ in range(R+1)] Vss [[0]*(C+1) for _ in range(R+1)] for _ in range(K):
        r, c, v = map(int, input().split())
        Vss[r][c] = v

     _ range(K) range K r, c, v = map(int, input().split()) r map(int, input().split()) map int input().split() ().split () input split c v Vss[r][c] = v Vss[r][c] [r] Vss r c v dpMax = [0]*(C+1) dpMax [0]*(C+1) [0] 0 C+1 C 1 for i in range(1, R+1):
        dp0 = [0]*(C+1)
        dp1 = [-INF]*(C+1)
        dp2 = [-INF]*(C+1)
        dp3 = [-INF]*(C+1)
        for j in range(1, C+1):
            V = Vss[i][j]
            dp0[j] = max2(dp0[j-1], dpMax[j])
            dp1[j] = max2(dp0[j] + V, dp1[j-1])
            dp2[j] = max2(dp1[j-1] + V, dp2[j-1])
            dp3[j] = max2(dp2[j-1] + V, dp3[j-1])
            dpMax[j] = max(dp0[j], dp1[j], dp2[j], dp3[j])

     i range(1, R+1) range 1 R+1 R 1 dp0 = [0]*(C+1) dp0 [0]*(C+1) [0] 0 C+1 C 1 dp1 = [-INF]*(C+1) dp1 [-INF]*(C+1) [-INF] -INF INF C+1 C 1 dp2 = [-INF]*(C+1) dp2 [-INF]*(C+1) [-INF] -INF INF C+1 C 1 dp3 = [-INF]*(C+1) dp3 [-INF]*(C+1) [-INF] -INF INF C+1 C 1 for j in range(1, C+1):
            V = Vss[i][j]
            dp0[j] = max2(dp0[j-1], dpMax[j])
            dp1[j] = max2(dp0[j] + V, dp1[j-1])
            dp2[j] = max2(dp1[j-1] + V, dp2[j-1])
            dp3[j] = max2(dp2[j-1] + V, dp3[j-1])
            dpMax[j] = max(dp0[j], dp1[j], dp2[j], dp3[j])

     j range(1, C+1) range 1 C+1 C 1 V = Vss[i][j] V Vss[i][j] [i] Vss i j dp0[j] = max2(dp0[j-1], dpMax[j]) dp0[j] dp0 j max2(dp0[j-1], dpMax[j]) max2 dp0[j-1] dp0 j-1 j 1 dpMax[j] dpMax j dp1[j] = max2(dp0[j] + V, dp1[j-1]) dp1[j] dp1 j max2(dp0[j] + V, dp1[j-1]) max2 dp0[j] + V dp0[j] dp0 j V dp1[j-1] dp1 j-1 j 1 dp2[j] = max2(dp1[j-1] + V, dp2[j-1]) dp2[j] dp2 j max2(dp1[j-1] + V, dp2[j-1]) max2 dp1[j-1] + V dp1[j-1] dp1 j-1 j 1 V dp2[j-1] dp2 j-1 j 1 dp3[j] = max2(dp2[j-1] + V, dp3[j-1]) dp3[j] dp3 j max2(dp2[j-1] + V, dp3[j-1]) max2 dp2[j-1] + V dp2[j-1] dp2 j-1 j 1 V dp3[j-1] dp3 j-1 j 1 dpMax[j] = max(dp0[j], dp1[j], dp2[j], dp3[j]) dpMax[j] dpMax j max(dp0[j], dp1[j], dp2[j], dp3[j]) max dp0[j] dp0 j dp1[j] dp1 j dp2[j] dp2 j dp3[j] dp3 j ans = dpMax[C] ans dpMax[C] dpMax C print(ans) print ans solve() solve def solve():
    INF = float('inf')

    def max2(x, y): return x if x >= y else y

    R, C, K = map(int, input().split())
    Vss = [[0]*(C+1) for _ in range(R+1)]
    for _ in range(K):
        r, c, v = map(int, input().split())
        Vss[r][c] = v

    dpMax = [0]*(C+1)
    for i in range(1, R+1):
        dp0 = [0]*(C+1)
        dp1 = [-INF]*(C+1)
        dp2 = [-INF]*(C+1)
        dp3 = [-INF]*(C+1)
        for j in range(1, C+1):
            V = Vss[i][j]
            dp0[j] = max2(dp0[j-1], dpMax[j])
            dp1[j] = max2(dp0[j] + V, dp1[j-1])
            dp2[j] = max2(dp1[j-1] + V, dp2[j-1])
            dp3[j] = max2(dp2[j-1] + V, dp3[j-1])
            dpMax[j] = max(dp0[j], dp1[j], dp2[j], dp3[j])

    ans = dpMax[C]
    print(ans) def solve():
    INF = float('inf')

    def max2(x, y): return x if x >= y else y

    R, C, K = map(int, input().split())
    Vss = [[0]*(C+1) for _ in range(R+1)]
    for _ in range(K):
        r, c, v = map(int, input().split())
        Vss[r][c] = v

    dpMax = [0]*(C+1)
    for i in range(1, R+1):
        dp0 = [0]*(C+1)
        dp1 = [-INF]*(C+1)
        dp2 = [-INF]*(C+1)
        dp3 = [-INF]*(C+1)
        for j in range(1, C+1):
            V = Vss[i][j]
            dp0[j] = max2(dp0[j-1], dpMax[j])
            dp1[j] = max2(dp0[j] + V, dp1[j-1])
            dp2[j] = max2(dp1[j-1] + V, dp2[j-1])
            dp3[j] = max2(dp2[j-1] + V, dp3[j-1])
            dpMax[j] = max(dp0[j], dp1[j], dp2[j], dp3[j])

    ans = dpMax[C]
    print(ans) solve input = sys.stdin.readline sys.stdin.readline input
import sys
input = sys.stdin.readline

def solve():
    INF = float('inf')

    def max2(x, y): return x if x >= y else y

    R, C, K = map(int, input().split())
    Vss = [[0]*(C+1) for _ in range(R+1)]
    for _ in range(K):
        r, c, v = map(int, input().split())
        Vss[r][c] = v

    dpMax = [0]*(C+1)
    for i in range(1, R+1):
        dp0 = [0]*(C+1)
        dp1 = [-INF]*(C+1)
        dp2 = [-INF]*(C+1)
        dp3 = [-INF]*(C+1)
        for j in range(1, C+1):
            V = Vss[i][j]
            dp0[j] = max2(dp0[j-1], dpMax[j])
            dp1[j] = max2(dp0[j] + V, dp1[j-1])
            dp2[j] = max2(dp1[j-1] + V, dp2[j-1])
            dp3[j] = max2(dp2[j-1] + V, dp3[j-1])
            dpMax[j] = max(dp0[j], dp1[j], dp2[j], dp3[j])

    ans = dpMax[C]
    print(ans)


solve()
