def main():
    import sys
    from copy import deepcopy
    input = sys.stdin.readline
    R, C, K = [int(x) for x in input().strip().split()]
    G = [[0] * (C+1) for r in range(R+1)]
    for k in range(K):
        r, c, v = [int(x) for x in input().strip().split()]
        G[r][c] = v
    # for r in range(R+1):
    #     print(G[r])
    ans = [[[0] * 4 for _ in range(C+1)] for _ in range(2)]
    for r in range(1, R+1):
        for c in range(1, C+1):
            ans[r%2][c][0] = max(ans[(r-1)%2][c][-1], ans[r%2][c-1][0])
            for i in range(1, 4):
                ans[r%2][c][i] = max(ans[(r-1)%2][c][3], ans[r%2][c-1][i], ans[(r-1)%2][c][3]+G[r][c], ans[r%2][c-1][i-1]+G[r][c])

    print(max(ans[R%2][-1]))

if __name__ == '__main__':
    main() def main():
    import sys
    from copy import deepcopy
    input = sys.stdin.readline
    R, C, K = [int(x) for x in input().strip().split()]
    G = [[0] * (C+1) for r in range(R+1)]
    for k in range(K):
        r, c, v = [int(x) for x in input().strip().split()]
        G[r][c] = v
    # for r in range(R+1):
    #     print(G[r])
    ans = [[[0] * 4 for _ in range(C+1)] for _ in range(2)]
    for r in range(1, R+1):
        for c in range(1, C+1):
            ans[r%2][c][0] = max(ans[(r-1)%2][c][-1], ans[r%2][c-1][0])
            for i in range(1, 4):
                ans[r%2][c][i] = max(ans[(r-1)%2][c][3], ans[r%2][c-1][i], ans[(r-1)%2][c][3]+G[r][c], ans[r%2][c-1][i-1]+G[r][c])

    print(max(ans[R%2][-1])) main import sys sys from copy import deepcopy input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline int(x) for x in input().strip().split() for x in input().strip().split() x input().strip().split() ().strip().split ().strip() ().strip () input strip split for x in input().strip().split() int(x) int x R, C, K = [int(x) for x in input().strip().split()] R [int(x) for x in input().strip().split()] C K [0] * (C+1) for r in range(R+1) for r in range(R+1) r range(R+1) range R+1 R 1 for r in range(R+1) [0] * (C+1) [0] 0 C+1 C 1 G = [[0] * (C+1) for r in range(R+1)] G [[0] * (C+1) for r in range(R+1)] for k in range(K):
        r, c, v = [int(x) for x in input().strip().split()]
        G[r][c] = v
    # for r in range(R+1):
    #     print(G[r])
     k range(K) range K int(x) for x in input().strip().split() for x in input().strip().split() x input().strip().split() ().strip().split ().strip() ().strip () input strip split for x in input().strip().split() int(x) int x r, c, v = [int(x) for x in input().strip().split()] r [int(x) for x in input().strip().split()] c v G[r][c] = v G[r][c] [r] G r c v [[0] * 4 for _ in range(C+1)] for _ in range(2) for _ in range(2) _ range(2) range 2 for _ in range(2) [[0] * 4 for _ in range(C+1)] ans = [[[0] * 4 for _ in range(C+1)] for _ in range(2)] ans [[[0] * 4 for _ in range(C+1)] for _ in range(2)] for r in range(1, R+1):
        for c in range(1, C+1):
            ans[r%2][c][0] = max(ans[(r-1)%2][c][-1], ans[r%2][c-1][0])
            for i in range(1, 4):
                ans[r%2][c][i] = max(ans[(r-1)%2][c][3], ans[r%2][c-1][i], ans[(r-1)%2][c][3]+G[r][c], ans[r%2][c-1][i-1]+G[r][c])

     r range(1, R+1) range 1 R+1 R 1 for c in range(1, C+1):
            ans[r%2][c][0] = max(ans[(r-1)%2][c][-1], ans[r%2][c-1][0])
            for i in range(1, 4):
                ans[r%2][c][i] = max(ans[(r-1)%2][c][3], ans[r%2][c-1][i], ans[(r-1)%2][c][3]+G[r][c], ans[r%2][c-1][i-1]+G[r][c])

     c range(1, C+1) range 1 C+1 C 1 ans[r%2][c][0] = max(ans[(r-1)%2][c][-1], ans[r%2][c-1][0]) ans[r%2][c][0] [c] [r%2] ans r%2 r 2 c 0 max(ans[(r-1)%2][c][-1], ans[r%2][c-1][0]) max ans[(r-1)%2][c][-1] [c] [(r-1)%2] ans (r-1)%2 r-1 r 1 2 c -1 ans[r%2][c-1][0] [c-1] [r%2] ans r%2 r 2 c-1 c 1 0 for i in range(1, 4):
                ans[r%2][c][i] = max(ans[(r-1)%2][c][3], ans[r%2][c-1][i], ans[(r-1)%2][c][3]+G[r][c], ans[r%2][c-1][i-1]+G[r][c])

     i range(1, 4) range 1 4 ans[r%2][c][i] = max(ans[(r-1)%2][c][3], ans[r%2][c-1][i], ans[(r-1)%2][c][3]+G[r][c], ans[r%2][c-1][i-1]+G[r][c]) ans[r%2][c][i] [c] [r%2] ans r%2 r 2 c i max(ans[(r-1)%2][c][3], ans[r%2][c-1][i], ans[(r-1)%2][c][3]+G[r][c], ans[r%2][c-1][i-1]+G[r][c]) max ans[(r-1)%2][c][3] [c] [(r-1)%2] ans (r-1)%2 r-1 r 1 2 c 3 ans[r%2][c-1][i] [c-1] [r%2] ans r%2 r 2 c-1 c 1 i ans[(r-1)%2][c][3]+G[r][c] ans[(r-1)%2][c][3] [c] [(r-1)%2] ans (r-1)%2 r-1 r 1 2 c 3 G[r][c] [r] G r c ans[r%2][c-1][i-1]+G[r][c] ans[r%2][c-1][i-1] [c-1] [r%2] ans r%2 r 2 c-1 c 1 i-1 i 1 G[r][c] [r] G r c print(max(ans[R%2][-1])) print max(ans[R%2][-1]) max ans[R%2][-1] [R%2] ans R%2 R 2 -1 if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main def main():
    import sys
    from copy import deepcopy
    input = sys.stdin.readline
    R, C, K = [int(x) for x in input().strip().split()]
    G = [[0] * (C+1) for r in range(R+1)]
    for k in range(K):
        r, c, v = [int(x) for x in input().strip().split()]
        G[r][c] = v
    # for r in range(R+1):
    #     print(G[r])
    ans = [[[0] * 4 for _ in range(C+1)] for _ in range(2)]
    for r in range(1, R+1):
        for c in range(1, C+1):
            ans[r%2][c][0] = max(ans[(r-1)%2][c][-1], ans[r%2][c-1][0])
            for i in range(1, 4):
                ans[r%2][c][i] = max(ans[(r-1)%2][c][3], ans[r%2][c-1][i], ans[(r-1)%2][c][3]+G[r][c], ans[r%2][c-1][i-1]+G[r][c])

    print(max(ans[R%2][-1])) def main():
    import sys
    from copy import deepcopy
    input = sys.stdin.readline
    R, C, K = [int(x) for x in input().strip().split()]
    G = [[0] * (C+1) for r in range(R+1)]
    for k in range(K):
        r, c, v = [int(x) for x in input().strip().split()]
        G[r][c] = v
    # for r in range(R+1):
    #     print(G[r])
    ans = [[[0] * 4 for _ in range(C+1)] for _ in range(2)]
    for r in range(1, R+1):
        for c in range(1, C+1):
            ans[r%2][c][0] = max(ans[(r-1)%2][c][-1], ans[r%2][c-1][0])
            for i in range(1, 4):
                ans[r%2][c][i] = max(ans[(r-1)%2][c][3], ans[r%2][c-1][i], ans[(r-1)%2][c][3]+G[r][c], ans[r%2][c-1][i-1]+G[r][c])

    print(max(ans[R%2][-1])) main
def main():
    import sys
    from copy import deepcopy
    input = sys.stdin.readline
    R, C, K = [int(x) for x in input().strip().split()]
    G = [[0] * (C+1) for r in range(R+1)]
    for k in range(K):
        r, c, v = [int(x) for x in input().strip().split()]
        G[r][c] = v
    # for r in range(R+1):
    #     print(G[r])
    ans = [[[0] * 4 for _ in range(C+1)] for _ in range(2)]
    for r in range(1, R+1):
        for c in range(1, C+1):
            ans[r%2][c][0] = max(ans[(r-1)%2][c][-1], ans[r%2][c-1][0])
            for i in range(1, 4):
                ans[r%2][c][i] = max(ans[(r-1)%2][c][3], ans[r%2][c-1][i], ans[(r-1)%2][c][3]+G[r][c], ans[r%2][c-1][i-1]+G[r][c])

    print(max(ans[R%2][-1]))

if __name__ == '__main__':
    main()
