def main():

    import sys

    input = sys.stdin.readline



    H, W, K = list(map(int, input().split()))



    G = [[0] * W for _ in range(H)]

    for _ in range(K):

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

        G[r - 1][c - 1] = v



    pdp = [[0] * 4 for _ in range(W)]

    for r in range(H):

        dp = [[0] * 4 for _ in range(W)]

        left = [0] * 4

        for c in range(W):

            cell = dp[c]



            for k in range(4):

                cell[k] = left[k]



            up = max(pdp[c])

            if cell[0] < up:

                cell[0] = up



            for k in range(2, -1, -1):

                cell[k + 1] = max(

                    cell[k + 1],

                    cell[k] + G[r][c])

            left = cell

        pdp = dp



    # for k in range(4):

    #     for row in range(H):

    #         for col in range(W):

    #             print(dp[row][col][k], end=' ')

    #         print()

    #     print()



    # print(*G, sep='\n')



    ans = max(dp[-1])

    print(ans)





if __name__ == '__main__':

    main()

# https://atcoder.jp/contests/abc175/submissions/15965930



def main():

    import sys

    input = sys.stdin.readline



    H, W, K = list(map(int, input().split()))



    G = [[0] * W for _ in range(H)]

    for _ in range(K):

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

        G[r - 1][c - 1] = v



    dp0 = [0] * (W + 1)

    dp1 = [0] * (W + 1)

    dp2 = [0] * (W + 1)

    dp3 = [0] * (W + 1)

    # dpx:=行内取得x個以下の最大値

    # <cは更新済の同じ行の値

    # c<=は前の行の値



    for r in range(H):

        for c in range(W):

            v = G[r][c]



            dp0[c] = max(dp0[c], dp3[c])

            up = dp0[c] + v



            dp3[c] = max(dp3[c - 1], dp2[c - 1] + v, up)

            dp2[c] = max(dp2[c - 1], dp1[c - 1] + v, up)

            dp1[c] = max(dp1[c - 1], dp0[c - 1] + v, up)

            # 左から来て取らない

            # 左から来て取る

            # 上から来て取らない:=dp0

            # 上から来て取る:=dpx(x>0)



            # print(f'{dp0=}')

            # print(f'{dp1=}')

            # print(f'{dp2=}')

            # print(f'{dp3=}')

            # print('*******************')



    print((dp3[-2]))





if __name__ == '__main__':

    main()

def main():
    import sys

    input = sys.stdin.readline
    H, W, K = list(map(int, input().split()))
    G = [[0] * W for _ in range(H)]
    for _ in range(K):
        r, c, v = list(map(int, input().split()))
        G[r - 1][c - 1] = v
    pdp = [[0] * 4 for _ in range(W)]
    for r in range(H):
        dp = [[0] * 4 for _ in range(W)]
        left = [0] * 4
        for c in range(W):
            cell = dp[c]
            for k in range(4):
                cell[k] = left[k]
            up = max(pdp[c])
            if cell[0] < up:
                cell[0] = up
            for k in range(2, -1, -1):
                cell[k + 1] = max(cell[k + 1], cell[k] + G[r][c])
            left = cell
        pdp = dp
    # for k in range(4):
    #     for row in range(H):
    #         for col in range(W):
    #             print(dp[row][col][k], end=' ')
    #         print()
    #     print()
    # print(*G, sep='\n')
    ans = max(dp[-1])
    print(ans)


if __name__ == "__main__":
    main()

# https://atcoder.jp/contests/abc175/submissions/15965930
def main():
    import sys

    input = sys.stdin.readline
    H, W, K = list(map(int, input().split()))
    G = [[0] * W for _ in range(H)]
    for _ in range(K):
        r, c, v = list(map(int, input().split()))
        G[r - 1][c - 1] = v
    dp0 = [0] * (W + 1)
    dp1 = [0] * (W + 1)
    dp2 = [0] * (W + 1)
    dp3 = [0] * (W + 1)
    # dpx:=行内取得x個以下の最大値
    # <cは更新済の同じ行の値
    # c<=は前の行の値
    for r in range(H):
        for c in range(W):
            v = G[r][c]
            dp0[c] = max(dp0[c], dp3[c])
            up = dp0[c] + v
            dp3[c] = max(dp3[c - 1], dp2[c - 1] + v, up)
            dp2[c] = max(dp2[c - 1], dp1[c - 1] + v, up)
            dp1[c] = max(dp1[c - 1], dp0[c - 1] + v, up)
            # 左から来て取らない
            # 左から来て取る
            # 上から来て取らない:=dp0
            # 上から来て取る:=dpx(x>0)
            # print(f'{dp0=}')
            # print(f'{dp1=}')
            # print(f'{dp2=}')
            # print(f'{dp3=}')
            # print('*******************')
    print((dp3[-2]))


if __name__ == "__main__":
    main()

+# https://atcoder.jp/contests/abc175/submissions/15965930 -    pdp = [[0] * 4 for _ in range(W)] +    dp0 = [0] * (W + 1) +    dp1 = [0] * (W + 1) +    dp2 = [0] * (W + 1) +    dp3 = [0] * (W + 1) +    # dpx:=行内取得x個以下の最大値 +    # <cは更新済の同じ行の値 +    # c<=は前の行の値 -        dp = [[0] * 4 for _ in range(W)] -        left = [0] * 4 -            cell = dp[c] -            for k in range(4): -                cell[k] = left[k] -            up = max(pdp[c]) -            if cell[0] < up: -                cell[0] = up -            for k in range(2, -1, -1): -                cell[k + 1] = max(cell[k + 1], cell[k] + G[r][c]) -            left = cell -        pdp = dp -    # for k in range(4): -    #     for row in range(H): -    #         for col in range(W): -    #             print(dp[row][col][k], end=' ') -    #         print() -    #     print() -    # print(*G, sep='\n') -    ans = max(dp[-1]) -    print(ans) +            v = G[r][c] +            dp0[c] = max(dp0[c], dp3[c]) +            up = dp0[c] + v +            dp3[c] = max(dp3[c - 1], dp2[c - 1] + v, up) +            dp2[c] = max(dp2[c - 1], dp1[c - 1] + v, up) +            dp1[c] = max(dp1[c - 1], dp0[c - 1] + v, up) +            # 左から来て取らない +            # 左から来て取る +            # 上から来て取らない:=dp0 +            # 上から来て取る:=dpx(x>0) +            # print(f'{dp0=}') +            # print(f'{dp1=}') +            # print(f'{dp2=}') +            # print(f'{dp3=}') +            # print('*******************') +    print((dp3[-2]))