def solve():
    R,C,K = map(int, input().split())
    #value = [[0 for _ in range(C)] for _ in range(R)]
    dp = [[[0 for _ in range(C+1)] for _ in range (R+1)] for _ in range(5)]
    for _ in range(K):
        r,c,v = map(int, input().split())
        dp[4][r][c] = v

    #print(value)
    #print(dp)

    for r in range(1, R+1):
        for c in range(1, C+1):
            v = dp[4][r][c]
            prow = max(dp[0][r-1][c], dp[1][r-1][c], dp[2][r-1][c], dp[3][r-1][c])
            if v == 0: # no item
                dp[0][r][c] = max(prow, dp[0][r][c-1])
                dp[1][r][c] = dp[1][r][c-1]
                dp[2][r][c] = dp[2][r][c-1]
                dp[3][r][c] = dp[3][r][c-1]
            else:
                dp[0][r][c] = max(prow, dp[0][r][c-1])
                dp[1][r][c] = max(dp[1][r][c-1], dp[0][r][c-1] + v, prow + v)
                dp[2][r][c] = max(dp[2][r][c-1], dp[1][r][c-1] + v)
                dp[3][r][c] = max(dp[3][r][c-1], dp[2][r][c-1] + v)

    #print(dp)
    print(max(dp[0][R][C], dp[1][R][C], dp[2][R][C], dp[3][R][C]))

solve() def solve():
    R,C,K = map(int, input().split())
    #value = [[0 for _ in range(C)] for _ in range(R)]
    dp = [[[0 for _ in range(C+1)] for _ in range (R+1)] for _ in range(5)]
    for _ in range(K):
        r,c,v = map(int, input().split())
        dp[4][r][c] = v

    #print(value)
    #print(dp)

    for r in range(1, R+1):
        for c in range(1, C+1):
            v = dp[4][r][c]
            prow = max(dp[0][r-1][c], dp[1][r-1][c], dp[2][r-1][c], dp[3][r-1][c])
            if v == 0: # no item
                dp[0][r][c] = max(prow, dp[0][r][c-1])
                dp[1][r][c] = dp[1][r][c-1]
                dp[2][r][c] = dp[2][r][c-1]
                dp[3][r][c] = dp[3][r][c-1]
            else:
                dp[0][r][c] = max(prow, dp[0][r][c-1])
                dp[1][r][c] = max(dp[1][r][c-1], dp[0][r][c-1] + v, prow + v)
                dp[2][r][c] = max(dp[2][r][c-1], dp[1][r][c-1] + v)
                dp[3][r][c] = max(dp[3][r][c-1], dp[2][r][c-1] + v)

    #print(dp)
    print(max(dp[0][R][C], dp[1][R][C], dp[2][R][C], dp[3][R][C])) solve R,C,K = map(int, input().split()) R map(int, input().split()) map int input().split() ().split () input split C K [[0 for _ in range(C+1)] for _ in range (R+1)] for _ in range(5) for _ in range(5) _ range(5) range 5 for _ in range(5) [[0 for _ in range(C+1)] for _ in range (R+1)] dp = [[[0 for _ in range(C+1)] for _ in range (R+1)] for _ in range(5)] dp [[[0 for _ in range(C+1)] for _ in range (R+1)] for _ in range(5)] for _ in range(K):
        r,c,v = map(int, input().split())
        dp[4][r][c] = v

    #print(value)
    #print(dp)

     _ 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 dp[4][r][c] = v dp[4][r][c] [r] [4] dp 4 r c v for r in range(1, R+1):
        for c in range(1, C+1):
            v = dp[4][r][c]
            prow = max(dp[0][r-1][c], dp[1][r-1][c], dp[2][r-1][c], dp[3][r-1][c])
            if v == 0: # no item
                dp[0][r][c] = max(prow, dp[0][r][c-1])
                dp[1][r][c] = dp[1][r][c-1]
                dp[2][r][c] = dp[2][r][c-1]
                dp[3][r][c] = dp[3][r][c-1]
            else:
                dp[0][r][c] = max(prow, dp[0][r][c-1])
                dp[1][r][c] = max(dp[1][r][c-1], dp[0][r][c-1] + v, prow + v)
                dp[2][r][c] = max(dp[2][r][c-1], dp[1][r][c-1] + v)
                dp[3][r][c] = max(dp[3][r][c-1], dp[2][r][c-1] + v)

    #print(dp)
     r range(1, R+1) range 1 R+1 R 1 for c in range(1, C+1):
            v = dp[4][r][c]
            prow = max(dp[0][r-1][c], dp[1][r-1][c], dp[2][r-1][c], dp[3][r-1][c])
            if v == 0: # no item
                dp[0][r][c] = max(prow, dp[0][r][c-1])
                dp[1][r][c] = dp[1][r][c-1]
                dp[2][r][c] = dp[2][r][c-1]
                dp[3][r][c] = dp[3][r][c-1]
            else:
                dp[0][r][c] = max(prow, dp[0][r][c-1])
                dp[1][r][c] = max(dp[1][r][c-1], dp[0][r][c-1] + v, prow + v)
                dp[2][r][c] = max(dp[2][r][c-1], dp[1][r][c-1] + v)
                dp[3][r][c] = max(dp[3][r][c-1], dp[2][r][c-1] + v)

    #print(dp)
     c range(1, C+1) range 1 C+1 C 1 v = dp[4][r][c] v dp[4][r][c] [r] [4] dp 4 r c prow = max(dp[0][r-1][c], dp[1][r-1][c], dp[2][r-1][c], dp[3][r-1][c]) prow max(dp[0][r-1][c], dp[1][r-1][c], dp[2][r-1][c], dp[3][r-1][c]) max dp[0][r-1][c] [r-1] [0] dp 0 r-1 r 1 c dp[1][r-1][c] [r-1] [1] dp 1 r-1 r 1 c dp[2][r-1][c] [r-1] [2] dp 2 r-1 r 1 c dp[3][r-1][c] [r-1] [3] dp 3 r-1 r 1 c if v == 0: # no item
                dp[0][r][c] = max(prow, dp[0][r][c-1])
                dp[1][r][c] = dp[1][r][c-1]
                dp[2][r][c] = dp[2][r][c-1]
                dp[3][r][c] = dp[3][r][c-1]
            else:
                dp[0][r][c] = max(prow, dp[0][r][c-1])
                dp[1][r][c] = max(dp[1][r][c-1], dp[0][r][c-1] + v, prow + v)
                dp[2][r][c] = max(dp[2][r][c-1], dp[1][r][c-1] + v)
                dp[3][r][c] = max(dp[3][r][c-1], dp[2][r][c-1] + v)

    #print(dp)
     v == 0 v 0 dp[0][r][c] = max(prow, dp[0][r][c-1]) dp[0][r][c] [r] [0] dp 0 r c max(prow, dp[0][r][c-1]) max prow dp[0][r][c-1] [r] [0] dp 0 r c-1 c 1 dp[1][r][c] = dp[1][r][c-1] dp[1][r][c] [r] [1] dp 1 r c dp[1][r][c-1] [r] [1] dp 1 r c-1 c 1 dp[2][r][c] = dp[2][r][c-1] dp[2][r][c] [r] [2] dp 2 r c dp[2][r][c-1] [r] [2] dp 2 r c-1 c 1 dp[3][r][c] = dp[3][r][c-1] dp[3][r][c] [r] [3] dp 3 r c dp[3][r][c-1] [r] [3] dp 3 r c-1 c 1 dp[0][r][c] = max(prow, dp[0][r][c-1]) dp[0][r][c] [r] [0] dp 0 r c max(prow, dp[0][r][c-1]) max prow dp[0][r][c-1] [r] [0] dp 0 r c-1 c 1 dp[1][r][c] = max(dp[1][r][c-1], dp[0][r][c-1] + v, prow + v) dp[1][r][c] [r] [1] dp 1 r c max(dp[1][r][c-1], dp[0][r][c-1] + v, prow + v) max dp[1][r][c-1] [r] [1] dp 1 r c-1 c 1 dp[0][r][c-1] + v dp[0][r][c-1] [r] [0] dp 0 r c-1 c 1 v prow + v prow v dp[2][r][c] = max(dp[2][r][c-1], dp[1][r][c-1] + v) dp[2][r][c] [r] [2] dp 2 r c max(dp[2][r][c-1], dp[1][r][c-1] + v) max dp[2][r][c-1] [r] [2] dp 2 r c-1 c 1 dp[1][r][c-1] + v dp[1][r][c-1] [r] [1] dp 1 r c-1 c 1 v dp[3][r][c] = max(dp[3][r][c-1], dp[2][r][c-1] + v) dp[3][r][c] [r] [3] dp 3 r c max(dp[3][r][c-1], dp[2][r][c-1] + v) max dp[3][r][c-1] [r] [3] dp 3 r c-1 c 1 dp[2][r][c-1] + v dp[2][r][c-1] [r] [2] dp 2 r c-1 c 1 v print(max(dp[0][R][C], dp[1][R][C], dp[2][R][C], dp[3][R][C])) print max(dp[0][R][C], dp[1][R][C], dp[2][R][C], dp[3][R][C]) max dp[0][R][C] [R] [0] dp 0 R C dp[1][R][C] [R] [1] dp 1 R C dp[2][R][C] [R] [2] dp 2 R C dp[3][R][C] [R] [3] dp 3 R C solve() solve def solve():
    R,C,K = map(int, input().split())
    #value = [[0 for _ in range(C)] for _ in range(R)]
    dp = [[[0 for _ in range(C+1)] for _ in range (R+1)] for _ in range(5)]
    for _ in range(K):
        r,c,v = map(int, input().split())
        dp[4][r][c] = v

    #print(value)
    #print(dp)

    for r in range(1, R+1):
        for c in range(1, C+1):
            v = dp[4][r][c]
            prow = max(dp[0][r-1][c], dp[1][r-1][c], dp[2][r-1][c], dp[3][r-1][c])
            if v == 0: # no item
                dp[0][r][c] = max(prow, dp[0][r][c-1])
                dp[1][r][c] = dp[1][r][c-1]
                dp[2][r][c] = dp[2][r][c-1]
                dp[3][r][c] = dp[3][r][c-1]
            else:
                dp[0][r][c] = max(prow, dp[0][r][c-1])
                dp[1][r][c] = max(dp[1][r][c-1], dp[0][r][c-1] + v, prow + v)
                dp[2][r][c] = max(dp[2][r][c-1], dp[1][r][c-1] + v)
                dp[3][r][c] = max(dp[3][r][c-1], dp[2][r][c-1] + v)

    #print(dp)
    print(max(dp[0][R][C], dp[1][R][C], dp[2][R][C], dp[3][R][C])) def solve():
    R,C,K = map(int, input().split())
    #value = [[0 for _ in range(C)] for _ in range(R)]
    dp = [[[0 for _ in range(C+1)] for _ in range (R+1)] for _ in range(5)]
    for _ in range(K):
        r,c,v = map(int, input().split())
        dp[4][r][c] = v

    #print(value)
    #print(dp)

    for r in range(1, R+1):
        for c in range(1, C+1):
            v = dp[4][r][c]
            prow = max(dp[0][r-1][c], dp[1][r-1][c], dp[2][r-1][c], dp[3][r-1][c])
            if v == 0: # no item
                dp[0][r][c] = max(prow, dp[0][r][c-1])
                dp[1][r][c] = dp[1][r][c-1]
                dp[2][r][c] = dp[2][r][c-1]
                dp[3][r][c] = dp[3][r][c-1]
            else:
                dp[0][r][c] = max(prow, dp[0][r][c-1])
                dp[1][r][c] = max(dp[1][r][c-1], dp[0][r][c-1] + v, prow + v)
                dp[2][r][c] = max(dp[2][r][c-1], dp[1][r][c-1] + v)
                dp[3][r][c] = max(dp[3][r][c-1], dp[2][r][c-1] + v)

    #print(dp)
    print(max(dp[0][R][C], dp[1][R][C], dp[2][R][C], dp[3][R][C])) solve
def solve():
    R,C,K = map(int, input().split())
    #value = [[0 for _ in range(C)] for _ in range(R)]
    dp = [[[0 for _ in range(C+1)] for _ in range (R+1)] for _ in range(5)]
    for _ in range(K):
        r,c,v = map(int, input().split())
        dp[4][r][c] = v

    #print(value)
    #print(dp)

    for r in range(1, R+1):
        for c in range(1, C+1):
            v = dp[4][r][c]
            prow = max(dp[0][r-1][c], dp[1][r-1][c], dp[2][r-1][c], dp[3][r-1][c])
            if v == 0: # no item
                dp[0][r][c] = max(prow, dp[0][r][c-1])
                dp[1][r][c] = dp[1][r][c-1]
                dp[2][r][c] = dp[2][r][c-1]
                dp[3][r][c] = dp[3][r][c-1]
            else:
                dp[0][r][c] = max(prow, dp[0][r][c-1])
                dp[1][r][c] = max(dp[1][r][c-1], dp[0][r][c-1] + v, prow + v)
                dp[2][r][c] = max(dp[2][r][c-1], dp[1][r][c-1] + v)
                dp[3][r][c] = max(dp[3][r][c-1], dp[2][r][c-1] + v)

    #print(dp)
    print(max(dp[0][R][C], dp[1][R][C], dp[2][R][C], dp[3][R][C]))

solve()