# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub


import sys
sys.setrecursionlimit(10**6)
# buff_readline = sys.stdin.buffer.readline
buff_readline = sys.stdin.readline
readline = sys.stdin.readline

INF = 2**62-1


def read_int():
    return int(buff_readline())


def read_int_n():
    return list(map(int, buff_readline().split()))


def read_float():
    return float(buff_readline())


def read_float_n():
    return list(map(float, buff_readline().split()))


def read_str():
    return readline().strip()


def read_str_n():
    return readline().strip().split()


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(R, C, K, RCV):
    V = [[0] * C for _ in range(R)]
    for r, c, v in RCV:
        V[r-1][c-1] = v
    memo = [[[0] * (C+1) for _ in range(R+1)] for __ in range(4)]

    for i in range(R):
        for j in range(C):
            for p in range(4):
                memo[p][i][j+1] = max(memo[p][i][j+1], memo[p][i][j])
                memo[0][i+1][j] = max(memo[0][i+1][j], memo[p][i][j])
                if p != 3:
                    memo[p+1][i][j+1] = max(memo[p+1][i][j+1], memo[p][i][j] + V[i][j])
                    memo[0][i+1][j] = max(memo[0][i+1][j], memo[p][i][j] + V[i][j])

    return max(memo[0][-1])


def main():
    R, C, K = read_int_n()
    RCV = [read_int_n() for _ in range(K)]
    print(slv(R, C, K, RCV))


if __name__ == '__main__':
    main() import bisect bisect import heapq heapq import math math import random random from collections import Counter, defaultdict, deque from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal from functools import lru_cache, reduce from itertools import combinations, combinations_with_replacement, product, permutations from operator import add, mul, sub import sys sys sys.setrecursionlimit(10**6) sys.setrecursionlimit sys setrecursionlimit 10**6 10 6 buff_readline = sys.stdin.readline buff_readline sys.stdin.readline sys.stdin sys stdin readline readline = sys.stdin.readline readline sys.stdin.readline sys.stdin sys stdin readline INF = 2**62-1 INF 2**62-1 2**62 2 62 1 def read_int():
    return int(buff_readline()) read_int return int(buff_readline()) int(buff_readline()) int buff_readline() buff_readline def read_int_n():
    return list(map(int, buff_readline().split())) read_int_n return list(map(int, buff_readline().split())) list(map(int, buff_readline().split())) list map(int, buff_readline().split()) map int buff_readline().split() ().split () buff_readline split def read_float():
    return float(buff_readline()) read_float return float(buff_readline()) float(buff_readline()) float buff_readline() buff_readline def read_float_n():
    return list(map(float, buff_readline().split())) read_float_n return list(map(float, buff_readline().split())) list(map(float, buff_readline().split())) list map(float, buff_readline().split()) map float buff_readline().split() ().split () buff_readline split def read_str():
    return readline().strip() read_str return readline().strip() readline().strip() ().strip () readline strip def read_str_n():
    return readline().strip().split() read_str_n return readline().strip().split() readline().strip().split() ().strip().split ().strip() ().strip () readline strip split def error_print(*args):
    print(*args, file=sys.stderr) error_print print(*args, file=sys.stderr) print *args args file=sys.stderr file sys.stderr sys stderr *args def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap mt import time time def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

     wrap s = time.time() s time.time() time.time time time ret = f(*args, **kwargs) ret f(*args, **kwargs) f *args args **kwargs kwargs e = time.time() e time.time() time.time time time error_print(e - s, 'sec') error_print e - s e s 'sec' return ret ret *args **kwargs return wrap wrap f f def slv(R, C, K, RCV):
    V = [[0] * C for _ in range(R)]
    for r, c, v in RCV:
        V[r-1][c-1] = v
    memo = [[[0] * (C+1) for _ in range(R+1)] for __ in range(4)]

    for i in range(R):
        for j in range(C):
            for p in range(4):
                memo[p][i][j+1] = max(memo[p][i][j+1], memo[p][i][j])
                memo[0][i+1][j] = max(memo[0][i+1][j], memo[p][i][j])
                if p != 3:
                    memo[p+1][i][j+1] = max(memo[p+1][i][j+1], memo[p][i][j] + V[i][j])
                    memo[0][i+1][j] = max(memo[0][i+1][j], memo[p][i][j] + V[i][j])

    return max(memo[0][-1]) slv [0] * C for _ in range(R) for _ in range(R) _ range(R) range R for _ in range(R) [0] * C [0] 0 C V = [[0] * C for _ in range(R)] V [[0] * C for _ in range(R)] for r, c, v in RCV:
        V[r-1][c-1] = v
     r c v RCV V[r-1][c-1] = v V[r-1][c-1] [r-1] V r-1 r 1 c-1 c 1 v [[0] * (C+1) for _ in range(R+1)] for __ in range(4) for __ in range(4) __ range(4) range 4 for __ in range(4) [[0] * (C+1) for _ in range(R+1)] memo = [[[0] * (C+1) for _ in range(R+1)] for __ in range(4)] memo [[[0] * (C+1) for _ in range(R+1)] for __ in range(4)] for i in range(R):
        for j in range(C):
            for p in range(4):
                memo[p][i][j+1] = max(memo[p][i][j+1], memo[p][i][j])
                memo[0][i+1][j] = max(memo[0][i+1][j], memo[p][i][j])
                if p != 3:
                    memo[p+1][i][j+1] = max(memo[p+1][i][j+1], memo[p][i][j] + V[i][j])
                    memo[0][i+1][j] = max(memo[0][i+1][j], memo[p][i][j] + V[i][j])

     i range(R) range R for j in range(C):
            for p in range(4):
                memo[p][i][j+1] = max(memo[p][i][j+1], memo[p][i][j])
                memo[0][i+1][j] = max(memo[0][i+1][j], memo[p][i][j])
                if p != 3:
                    memo[p+1][i][j+1] = max(memo[p+1][i][j+1], memo[p][i][j] + V[i][j])
                    memo[0][i+1][j] = max(memo[0][i+1][j], memo[p][i][j] + V[i][j])

     j range(C) range C for p in range(4):
                memo[p][i][j+1] = max(memo[p][i][j+1], memo[p][i][j])
                memo[0][i+1][j] = max(memo[0][i+1][j], memo[p][i][j])
                if p != 3:
                    memo[p+1][i][j+1] = max(memo[p+1][i][j+1], memo[p][i][j] + V[i][j])
                    memo[0][i+1][j] = max(memo[0][i+1][j], memo[p][i][j] + V[i][j])

     p range(4) range 4 memo[p][i][j+1] = max(memo[p][i][j+1], memo[p][i][j]) memo[p][i][j+1] [i] [p] memo p i j+1 j 1 max(memo[p][i][j+1], memo[p][i][j]) max memo[p][i][j+1] [i] [p] memo p i j+1 j 1 memo[p][i][j] [i] [p] memo p i j memo[0][i+1][j] = max(memo[0][i+1][j], memo[p][i][j]) memo[0][i+1][j] [i+1] [0] memo 0 i+1 i 1 j max(memo[0][i+1][j], memo[p][i][j]) max memo[0][i+1][j] [i+1] [0] memo 0 i+1 i 1 j memo[p][i][j] [i] [p] memo p i j if p != 3:
                    memo[p+1][i][j+1] = max(memo[p+1][i][j+1], memo[p][i][j] + V[i][j])
                    memo[0][i+1][j] = max(memo[0][i+1][j], memo[p][i][j] + V[i][j])

     p != 3 p 3 memo[p+1][i][j+1] = max(memo[p+1][i][j+1], memo[p][i][j] + V[i][j]) memo[p+1][i][j+1] [i] [p+1] memo p+1 p 1 i j+1 j 1 max(memo[p+1][i][j+1], memo[p][i][j] + V[i][j]) max memo[p+1][i][j+1] [i] [p+1] memo p+1 p 1 i j+1 j 1 memo[p][i][j] + V[i][j] memo[p][i][j] [i] [p] memo p i j V[i][j] [i] V i j memo[0][i+1][j] = max(memo[0][i+1][j], memo[p][i][j] + V[i][j]) memo[0][i+1][j] [i+1] [0] memo 0 i+1 i 1 j max(memo[0][i+1][j], memo[p][i][j] + V[i][j]) max memo[0][i+1][j] [i+1] [0] memo 0 i+1 i 1 j memo[p][i][j] + V[i][j] memo[p][i][j] [i] [p] memo p i j V[i][j] [i] V i j return max(memo[0][-1]) max(memo[0][-1]) max memo[0][-1] [0] memo 0 -1 R R C C K K RCV RCV @mt slv mt slv def main():
    R, C, K = read_int_n()
    RCV = [read_int_n() for _ in range(K)]
    print(slv(R, C, K, RCV)) main R, C, K = read_int_n() R read_int_n() read_int_n C K read_int_n() for _ in range(K) for _ in range(K) _ range(K) range K for _ in range(K) read_int_n() read_int_n RCV = [read_int_n() for _ in range(K)] RCV [read_int_n() for _ in range(K)] print(slv(R, C, K, RCV)) print slv(R, C, K, RCV) slv R C K RCV if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap mt def error_print(*args):
    print(*args, file=sys.stderr) def error_print(*args):
    print(*args, file=sys.stderr) error_print INF = 2**62-1 2**62-1 INF def read_float():
    return float(buff_readline()) def read_float():
    return float(buff_readline()) read_float def read_int():
    return int(buff_readline()) def read_int():
    return int(buff_readline()) read_int def read_str():
    return readline().strip() def read_str():
    return readline().strip() read_str def read_str_n():
    return readline().strip().split() def read_str_n():
    return readline().strip().split() read_str_n buff_readline = sys.stdin.readline sys.stdin.readline buff_readline def slv(R, C, K, RCV):
    V = [[0] * C for _ in range(R)]
    for r, c, v in RCV:
        V[r-1][c-1] = v
    memo = [[[0] * (C+1) for _ in range(R+1)] for __ in range(4)]

    for i in range(R):
        for j in range(C):
            for p in range(4):
                memo[p][i][j+1] = max(memo[p][i][j+1], memo[p][i][j])
                memo[0][i+1][j] = max(memo[0][i+1][j], memo[p][i][j])
                if p != 3:
                    memo[p+1][i][j+1] = max(memo[p+1][i][j+1], memo[p][i][j] + V[i][j])
                    memo[0][i+1][j] = max(memo[0][i+1][j], memo[p][i][j] + V[i][j])

    return max(memo[0][-1]) def slv(R, C, K, RCV):
    V = [[0] * C for _ in range(R)]
    for r, c, v in RCV:
        V[r-1][c-1] = v
    memo = [[[0] * (C+1) for _ in range(R+1)] for __ in range(4)]

    for i in range(R):
        for j in range(C):
            for p in range(4):
                memo[p][i][j+1] = max(memo[p][i][j+1], memo[p][i][j])
                memo[0][i+1][j] = max(memo[0][i+1][j], memo[p][i][j])
                if p != 3:
                    memo[p+1][i][j+1] = max(memo[p+1][i][j+1], memo[p][i][j] + V[i][j])
                    memo[0][i+1][j] = max(memo[0][i+1][j], memo[p][i][j] + V[i][j])

    return max(memo[0][-1]) slv def main():
    R, C, K = read_int_n()
    RCV = [read_int_n() for _ in range(K)]
    print(slv(R, C, K, RCV)) def main():
    R, C, K = read_int_n()
    RCV = [read_int_n() for _ in range(K)]
    print(slv(R, C, K, RCV)) main def read_float_n():
    return list(map(float, buff_readline().split())) def read_float_n():
    return list(map(float, buff_readline().split())) read_float_n def read_int_n():
    return list(map(int, buff_readline().split())) def read_int_n():
    return list(map(int, buff_readline().split())) read_int_n readline = sys.stdin.readline sys.stdin.readline readline
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub


import sys
sys.setrecursionlimit(10**6)
# buff_readline = sys.stdin.buffer.readline
buff_readline = sys.stdin.readline
readline = sys.stdin.readline

INF = 2**62-1


def read_int():
    return int(buff_readline())


def read_int_n():
    return list(map(int, buff_readline().split()))


def read_float():
    return float(buff_readline())


def read_float_n():
    return list(map(float, buff_readline().split()))


def read_str():
    return readline().strip()


def read_str_n():
    return readline().strip().split()


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(R, C, K, RCV):
    V = [[0] * C for _ in range(R)]
    for r, c, v in RCV:
        V[r-1][c-1] = v
    memo = [[[0] * (C+1) for _ in range(R+1)] for __ in range(4)]

    for i in range(R):
        for j in range(C):
            for p in range(4):
                memo[p][i][j+1] = max(memo[p][i][j+1], memo[p][i][j])
                memo[0][i+1][j] = max(memo[0][i+1][j], memo[p][i][j])
                if p != 3:
                    memo[p+1][i][j+1] = max(memo[p+1][i][j+1], memo[p][i][j] + V[i][j])
                    memo[0][i+1][j] = max(memo[0][i+1][j], memo[p][i][j] + V[i][j])

    return max(memo[0][-1])


def main():
    R, C, K = read_int_n()
    RCV = [read_int_n() for _ in range(K)]
    print(slv(R, C, K, RCV))


if __name__ == '__main__':
    main()
