import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    R, C, K, *RCV = map(int, read().split())

    item = [[0] * C for _ in range(R)]
    for r, c, v in zip(*[iter(RCV)] * 3):
        item[r - 1][c - 1] = v

    dp = [0] * (C + 1)
    for i in range(R):
        value = [0] * 4
        for j in range(C):
            for k in range(4):
                if value[k] < dp[j + 1]:
                    value[k] = dp[j + 1]
                else:
                    break
            if item[i][j] > 0:
                for k in range(2, -1, -1):
                    if value[k + 1] < value[k] + item[i][j]:
                        value[k + 1] = value[k] + item[i][j]
            dp[j + 1] = value[3]

    print(dp[C])

    return


if __name__ == '__main__':
    main() import sys sys read = sys.stdin.read read sys.stdin.read sys.stdin sys stdin read readline = sys.stdin.readline readline sys.stdin.readline sys.stdin sys stdin readline readlines = sys.stdin.readlines readlines sys.stdin.readlines sys.stdin sys stdin readlines sys.setrecursionlimit(10 ** 9) sys.setrecursionlimit sys setrecursionlimit 10 ** 9 10 9 INF = 1 << 60 INF 1 << 60 1 60 MOD = 1000000007 MOD 1000000007 def main():
    R, C, K, *RCV = map(int, read().split())

    item = [[0] * C for _ in range(R)]
    for r, c, v in zip(*[iter(RCV)] * 3):
        item[r - 1][c - 1] = v

    dp = [0] * (C + 1)
    for i in range(R):
        value = [0] * 4
        for j in range(C):
            for k in range(4):
                if value[k] < dp[j + 1]:
                    value[k] = dp[j + 1]
                else:
                    break
            if item[i][j] > 0:
                for k in range(2, -1, -1):
                    if value[k + 1] < value[k] + item[i][j]:
                        value[k + 1] = value[k] + item[i][j]
            dp[j + 1] = value[3]

    print(dp[C])

    return main R, C, K, *RCV = map(int, read().split()) R map(int, read().split()) map int read().split() ().split () read split C K *RCV RCV [0] * C for _ in range(R) for _ in range(R) _ range(R) range R for _ in range(R) [0] * C [0] 0 C item = [[0] * C for _ in range(R)] item [[0] * C for _ in range(R)] for r, c, v in zip(*[iter(RCV)] * 3):
        item[r - 1][c - 1] = v

     r c v zip(*[iter(RCV)] * 3) zip *[iter(RCV)] * 3 [iter(RCV)] * 3 [iter(RCV)] iter(RCV) iter RCV 3 item[r - 1][c - 1] = v item[r - 1][c - 1] [r - 1] item r - 1 r 1 c - 1 c 1 v dp = [0] * (C + 1) dp [0] * (C + 1) [0] 0 C + 1 C 1 for i in range(R):
        value = [0] * 4
        for j in range(C):
            for k in range(4):
                if value[k] < dp[j + 1]:
                    value[k] = dp[j + 1]
                else:
                    break
            if item[i][j] > 0:
                for k in range(2, -1, -1):
                    if value[k + 1] < value[k] + item[i][j]:
                        value[k + 1] = value[k] + item[i][j]
            dp[j + 1] = value[3]

     i range(R) range R value = [0] * 4 value [0] * 4 [0] 0 4 for j in range(C):
            for k in range(4):
                if value[k] < dp[j + 1]:
                    value[k] = dp[j + 1]
                else:
                    break
            if item[i][j] > 0:
                for k in range(2, -1, -1):
                    if value[k + 1] < value[k] + item[i][j]:
                        value[k + 1] = value[k] + item[i][j]
            dp[j + 1] = value[3]

     j range(C) range C for k in range(4):
                if value[k] < dp[j + 1]:
                    value[k] = dp[j + 1]
                else:
                    break
             k range(4) range 4 if value[k] < dp[j + 1]:
                    value[k] = dp[j + 1]
                else:
                    break
             value[k] < dp[j + 1] value[k] value k dp[j + 1] dp j + 1 j 1 value[k] = dp[j + 1] value[k] value k dp[j + 1] dp j + 1 j 1 break if item[i][j] > 0:
                for k in range(2, -1, -1):
                    if value[k + 1] < value[k] + item[i][j]:
                        value[k + 1] = value[k] + item[i][j]
             item[i][j] > 0 item[i][j] [i] item i j 0 for k in range(2, -1, -1):
                    if value[k + 1] < value[k] + item[i][j]:
                        value[k + 1] = value[k] + item[i][j]
             k range(2, -1, -1) range 2 -1 -1 if value[k + 1] < value[k] + item[i][j]:
                        value[k + 1] = value[k] + item[i][j]
             value[k + 1] < value[k] + item[i][j] value[k + 1] value k + 1 k 1 value[k] + item[i][j] value[k] value k item[i][j] [i] item i j value[k + 1] = value[k] + item[i][j] value[k + 1] value k + 1 k 1 value[k] + item[i][j] value[k] value k item[i][j] [i] item i j dp[j + 1] = value[3] dp[j + 1] dp j + 1 j 1 value[3] value 3 print(dp[C]) print dp[C] dp C return if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main readline = sys.stdin.readline sys.stdin.readline readline INF = 1 << 60 1 << 60 INF def main():
    R, C, K, *RCV = map(int, read().split())

    item = [[0] * C for _ in range(R)]
    for r, c, v in zip(*[iter(RCV)] * 3):
        item[r - 1][c - 1] = v

    dp = [0] * (C + 1)
    for i in range(R):
        value = [0] * 4
        for j in range(C):
            for k in range(4):
                if value[k] < dp[j + 1]:
                    value[k] = dp[j + 1]
                else:
                    break
            if item[i][j] > 0:
                for k in range(2, -1, -1):
                    if value[k + 1] < value[k] + item[i][j]:
                        value[k + 1] = value[k] + item[i][j]
            dp[j + 1] = value[3]

    print(dp[C])

    return def main():
    R, C, K, *RCV = map(int, read().split())

    item = [[0] * C for _ in range(R)]
    for r, c, v in zip(*[iter(RCV)] * 3):
        item[r - 1][c - 1] = v

    dp = [0] * (C + 1)
    for i in range(R):
        value = [0] * 4
        for j in range(C):
            for k in range(4):
                if value[k] < dp[j + 1]:
                    value[k] = dp[j + 1]
                else:
                    break
            if item[i][j] > 0:
                for k in range(2, -1, -1):
                    if value[k + 1] < value[k] + item[i][j]:
                        value[k + 1] = value[k] + item[i][j]
            dp[j + 1] = value[3]

    print(dp[C])

    return main read = sys.stdin.read sys.stdin.read read readlines = sys.stdin.readlines sys.stdin.readlines readlines MOD = 1000000007 1000000007 MOD
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    R, C, K, *RCV = map(int, read().split())

    item = [[0] * C for _ in range(R)]
    for r, c, v in zip(*[iter(RCV)] * 3):
        item[r - 1][c - 1] = v

    dp = [0] * (C + 1)
    for i in range(R):
        value = [0] * 4
        for j in range(C):
            for k in range(4):
                if value[k] < dp[j + 1]:
                    value[k] = dp[j + 1]
                else:
                    break
            if item[i][j] > 0:
                for k in range(2, -1, -1):
                    if value[k + 1] < value[k] + item[i][j]:
                        value[k + 1] = value[k] + item[i][j]
            dp[j + 1] = value[3]

    print(dp[C])

    return


if __name__ == '__main__':
    main()
