import sys

sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def exit(*argv, **kwarg):
    print(*argv, **kwarg)
    sys.exit()


def mina(*argv, sub=1): return list(map(lambda x: x - sub, argv))
# 受け渡されたすべての要素からsubだけ引く.リストを*をつけて展開しておくこと


def a_int(): return int(read())


def ints(): return list(map(int, read().split()))


def read_col(H):
    '''H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret)))


def read_tuple(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque


'''
dp[i][j]...(0,0)からスタートして(i,j)に到達する経路のなかでの最大の価値
dp[i][j]=max(dp[i][j-1],dp[i-1][j]) + v[i][j]


dp[i][j][k] ... (0,0)からスタートして(i,j)に到達する経路のなかでi行目ですでにk(以下)個選んでいるときの最大の価値

遷移は、i,jのvを拾うときと拾わないときのmax
dp[i][j][k] = max(dp[i][j-1][k-1]+V[i,j], dp[i][j-1][k]
                  ) #k個のままのほうが価値が高いかk-1から拾ったほうが価値が高いか

上からの遷移 # 拾うか拾わないかでこうかな
dp[i][j][0]=max(dp[i][j-1][0],max_k(dp[i-1][j]))
dp[i][j][1]=max(dp[i][j-1][0],max_k(dp[i-1][j][k])+V[i][j])
'''

R, C, K = ints()
RCV = read_tuple(K)
V = [[0] * C for _ in ra(R)]
for r, c, v in RCV:
    V[r - 1][c - 1] = v

# dp = [[[0] * 4 for _ in ra(C)] for _ in ra(R)]
dp0 = [[0] * C for _ in ra(R)]
dp1 = [[0] * C for _ in ra(R)]
dp2 = [[0] * C for _ in ra(R)]
dp3 = [[0] * C for _ in ra(R)]

# dp[0][0][0] = 0
dp1[0][0] = V[0][0]
dp2[0][0] = V[0][0]
dp3[0][0] = V[0][0]

for j in ra(1, C):
    dp1[0][j] = max(dp1[0][j - 1], dp0[0][j - 1] + V[0][j])
    dp2[0][j] = max(dp2[0][j - 1], dp1[0][j - 1] + V[0][j])
    dp3[0][j] = max(dp3[0][j - 1], dp2[0][j - 1] + V[0][j])

for i in ra(1, R):
    dp0[i][0] = dp1[i - 1][0]
    dp1[i][0] = dp0[i][0] + V[i][0]
    dp2[i][0] = dp0[i][0] + V[i][0]
    dp3[i][0] = dp0[i][0] + V[i][0]


for i in ra(1, R):
    for j in ra(1, C):
        ma = max(dp0[i - 1][j],
                 dp1[i - 1][j],
                 dp2[i - 1][j],
                 dp3[i - 1][j])

        dp0[i][j] = max(dp0[i][j - 1],  # 左
                        ma)  # 上

        dp1[i][j] = max(dp0[i][j - 1] + V[i][j],  # 左から来て拾う
                        dp1[i][j - 1],  # 拾わないほうが大きい場合もある
                        ma + V[i][j])  # 上から来て拾う

        dp2[i][j] = max(dp1[i][j - 1] + V[i][j], dp2[i][j - 1])
        dp3[i][j] = max(dp2[i][j - 1] + V[i][j], dp3[i][j - 1])


print(max(dp0[R - 1][C - 1],
          dp1[R - 1][C - 1],
          dp2[R - 1][C - 1],
          dp3[R - 1][C - 1],
          ))

# print(*values, sep='\n')
# print(*dp, sep='\n')

# dp2 = [[-1] * C for _ in ra(R)]
# for i in ra(R):
#     for j in ra(C):
#         dp2[i][j] = max(dp[i][j])
# print(*dp2, sep='\n') import sys sys sys.setrecursionlimit(1 << 25) sys.setrecursionlimit sys setrecursionlimit 1 << 25 1 25 read = sys.stdin.readline read sys.stdin.readline sys.stdin sys stdin readline ra = range ra range enu = enumerate enu enumerate def exit(*argv, **kwarg):
    print(*argv, **kwarg)
    sys.exit() exit print(*argv, **kwarg) print *argv argv **kwarg kwarg sys.exit() sys.exit sys exit *argv **kwarg def mina(*argv, sub=1): return list(map(lambda x: x - sub, argv))
# 受け渡されたすべての要素からsubだけ引く.リストを*をつけて展開しておくこと mina sub=1 sub 1 *argv def a_int(): return int(read()) a_int def ints(): return list(map(int, read().split())) ints def read_col(H):
    '''H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret))) read_col '''H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合''' ret = [] ret [] for _ in range(H):
        ret.append(list(map(int, read().split())))
     _ range(H) range H ret.append(list(map(int, read().split()))) ret.append ret append list(map(int, read().split())) list map(int, read().split()) map int read().split() ().split () read split return tuple(map(list, zip(*ret))) tuple(map(list, zip(*ret))) tuple map(list, zip(*ret)) map list zip(*ret) zip *ret ret H H def read_tuple(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret read_tuple '''H is number of rows''' ret = [] ret [] for _ in range(H):
        ret.append(tuple(map(int, read().split())))
     _ range(H) range H ret.append(tuple(map(int, read().split()))) ret.append ret append tuple(map(int, read().split())) tuple map(int, read().split()) map int read().split() ().split () read split return ret ret H H MOD = 10**9 + 7 MOD 10**9 + 7 10**9 10 9 7 INF = 2**31 INF 2**31 2 31 from collections import defaultdict, Counter, deque '''
dp[i][j]...(0,0)からスタートして(i,j)に到達する経路のなかでの最大の価値
dp[i][j]=max(dp[i][j-1],dp[i-1][j]) + v[i][j]


dp[i][j][k] ... (0,0)からスタートして(i,j)に到達する経路のなかでi行目ですでにk(以下)個選んでいるときの最大の価値

遷移は、i,jのvを拾うときと拾わないときのmax
dp[i][j][k] = max(dp[i][j-1][k-1]+V[i,j], dp[i][j-1][k]
                  ) #k個のままのほうが価値が高いかk-1から拾ったほうが価値が高いか

上からの遷移 # 拾うか拾わないかでこうかな
dp[i][j][0]=max(dp[i][j-1][0],max_k(dp[i-1][j]))
dp[i][j][1]=max(dp[i][j-1][0],max_k(dp[i-1][j][k])+V[i][j])
''' R, C, K = ints() R ints() ints C K RCV = read_tuple(K) RCV read_tuple(K) read_tuple K [0] * C for _ in ra(R) for _ in ra(R) _ ra(R) ra R for _ in ra(R) [0] * C [0] 0 C V = [[0] * C for _ in ra(R)] V [[0] * C for _ in ra(R)] for r, c, v in RCV:
    V[r - 1][c - 1] = v

# dp = [[[0] * 4 for _ in ra(C)] for _ in ra(R)] 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 for _ in ra(R) for _ in ra(R) _ ra(R) ra R for _ in ra(R) [0] * C [0] 0 C dp0 = [[0] * C for _ in ra(R)] dp0 [[0] * C for _ in ra(R)] [0] * C for _ in ra(R) for _ in ra(R) _ ra(R) ra R for _ in ra(R) [0] * C [0] 0 C dp1 = [[0] * C for _ in ra(R)] dp1 [[0] * C for _ in ra(R)] [0] * C for _ in ra(R) for _ in ra(R) _ ra(R) ra R for _ in ra(R) [0] * C [0] 0 C dp2 = [[0] * C for _ in ra(R)] dp2 [[0] * C for _ in ra(R)] [0] * C for _ in ra(R) for _ in ra(R) _ ra(R) ra R for _ in ra(R) [0] * C [0] 0 C dp3 = [[0] * C for _ in ra(R)] dp3 [[0] * C for _ in ra(R)] dp1[0][0] = V[0][0] dp1[0][0] [0] dp1 0 0 V[0][0] [0] V 0 0 dp2[0][0] = V[0][0] dp2[0][0] [0] dp2 0 0 V[0][0] [0] V 0 0 dp3[0][0] = V[0][0] dp3[0][0] [0] dp3 0 0 V[0][0] [0] V 0 0 for j in ra(1, C):
    dp1[0][j] = max(dp1[0][j - 1], dp0[0][j - 1] + V[0][j])
    dp2[0][j] = max(dp2[0][j - 1], dp1[0][j - 1] + V[0][j])
    dp3[0][j] = max(dp3[0][j - 1], dp2[0][j - 1] + V[0][j]) j ra(1, C) ra 1 C dp1[0][j] = max(dp1[0][j - 1], dp0[0][j - 1] + V[0][j]) dp1[0][j] [0] dp1 0 j max(dp1[0][j - 1], dp0[0][j - 1] + V[0][j]) max dp1[0][j - 1] [0] dp1 0 j - 1 j 1 dp0[0][j - 1] + V[0][j] dp0[0][j - 1] [0] dp0 0 j - 1 j 1 V[0][j] [0] V 0 j dp2[0][j] = max(dp2[0][j - 1], dp1[0][j - 1] + V[0][j]) dp2[0][j] [0] dp2 0 j max(dp2[0][j - 1], dp1[0][j - 1] + V[0][j]) max dp2[0][j - 1] [0] dp2 0 j - 1 j 1 dp1[0][j - 1] + V[0][j] dp1[0][j - 1] [0] dp1 0 j - 1 j 1 V[0][j] [0] V 0 j dp3[0][j] = max(dp3[0][j - 1], dp2[0][j - 1] + V[0][j]) dp3[0][j] [0] dp3 0 j max(dp3[0][j - 1], dp2[0][j - 1] + V[0][j]) max dp3[0][j - 1] [0] dp3 0 j - 1 j 1 dp2[0][j - 1] + V[0][j] dp2[0][j - 1] [0] dp2 0 j - 1 j 1 V[0][j] [0] V 0 j for i in ra(1, R):
    dp0[i][0] = dp1[i - 1][0]
    dp1[i][0] = dp0[i][0] + V[i][0]
    dp2[i][0] = dp0[i][0] + V[i][0]
    dp3[i][0] = dp0[i][0] + V[i][0] i ra(1, R) ra 1 R dp0[i][0] = dp1[i - 1][0] dp0[i][0] [i] dp0 i 0 dp1[i - 1][0] [i - 1] dp1 i - 1 i 1 0 dp1[i][0] = dp0[i][0] + V[i][0] dp1[i][0] [i] dp1 i 0 dp0[i][0] + V[i][0] dp0[i][0] [i] dp0 i 0 V[i][0] [i] V i 0 dp2[i][0] = dp0[i][0] + V[i][0] dp2[i][0] [i] dp2 i 0 dp0[i][0] + V[i][0] dp0[i][0] [i] dp0 i 0 V[i][0] [i] V i 0 dp3[i][0] = dp0[i][0] + V[i][0] dp3[i][0] [i] dp3 i 0 dp0[i][0] + V[i][0] dp0[i][0] [i] dp0 i 0 V[i][0] [i] V i 0 for i in ra(1, R):
    for j in ra(1, C):
        ma = max(dp0[i - 1][j],
                 dp1[i - 1][j],
                 dp2[i - 1][j],
                 dp3[i - 1][j])

        dp0[i][j] = max(dp0[i][j - 1],  # 左
                        ma)  # 上

        dp1[i][j] = max(dp0[i][j - 1] + V[i][j],  # 左から来て拾う
                        dp1[i][j - 1],  # 拾わないほうが大きい場合もある
                        ma + V[i][j])  # 上から来て拾う

        dp2[i][j] = max(dp1[i][j - 1] + V[i][j], dp2[i][j - 1])
        dp3[i][j] = max(dp2[i][j - 1] + V[i][j], dp3[i][j - 1]) i ra(1, R) ra 1 R for j in ra(1, C):
        ma = max(dp0[i - 1][j],
                 dp1[i - 1][j],
                 dp2[i - 1][j],
                 dp3[i - 1][j])

        dp0[i][j] = max(dp0[i][j - 1],  # 左
                        ma)  # 上

        dp1[i][j] = max(dp0[i][j - 1] + V[i][j],  # 左から来て拾う
                        dp1[i][j - 1],  # 拾わないほうが大きい場合もある
                        ma + V[i][j])  # 上から来て拾う

        dp2[i][j] = max(dp1[i][j - 1] + V[i][j], dp2[i][j - 1])
        dp3[i][j] = max(dp2[i][j - 1] + V[i][j], dp3[i][j - 1]) j ra(1, C) ra 1 C ma = max(dp0[i - 1][j],
                 dp1[i - 1][j],
                 dp2[i - 1][j],
                 dp3[i - 1][j]) ma max(dp0[i - 1][j],
                 dp1[i - 1][j],
                 dp2[i - 1][j],
                 dp3[i - 1][j]) max dp0[i - 1][j] [i - 1] dp0 i - 1 i 1 j dp1[i - 1][j] [i - 1] dp1 i - 1 i 1 j dp2[i - 1][j] [i - 1] dp2 i - 1 i 1 j dp3[i - 1][j] [i - 1] dp3 i - 1 i 1 j dp0[i][j] = max(dp0[i][j - 1],  # 左
                        ma) dp0[i][j] [i] dp0 i j max(dp0[i][j - 1],  # 左
                        ma) max dp0[i][j - 1] [i] dp0 i j - 1 j 1 ma dp1[i][j] = max(dp0[i][j - 1] + V[i][j],  # 左から来て拾う
                        dp1[i][j - 1],  # 拾わないほうが大きい場合もある
                        ma + V[i][j]) dp1[i][j] [i] dp1 i j max(dp0[i][j - 1] + V[i][j],  # 左から来て拾う
                        dp1[i][j - 1],  # 拾わないほうが大きい場合もある
                        ma + V[i][j]) max dp0[i][j - 1] + V[i][j] dp0[i][j - 1] [i] dp0 i j - 1 j 1 V[i][j] [i] V i j dp1[i][j - 1] [i] dp1 i j - 1 j 1 ma + V[i][j] ma V[i][j] [i] V i j dp2[i][j] = max(dp1[i][j - 1] + V[i][j], dp2[i][j - 1]) dp2[i][j] [i] dp2 i j max(dp1[i][j - 1] + V[i][j], dp2[i][j - 1]) max dp1[i][j - 1] + V[i][j] dp1[i][j - 1] [i] dp1 i j - 1 j 1 V[i][j] [i] V i j dp2[i][j - 1] [i] dp2 i j - 1 j 1 dp3[i][j] = max(dp2[i][j - 1] + V[i][j], dp3[i][j - 1]) dp3[i][j] [i] dp3 i j max(dp2[i][j - 1] + V[i][j], dp3[i][j - 1]) max dp2[i][j - 1] + V[i][j] dp2[i][j - 1] [i] dp2 i j - 1 j 1 V[i][j] [i] V i j dp3[i][j - 1] [i] dp3 i j - 1 j 1 print(max(dp0[R - 1][C - 1],
          dp1[R - 1][C - 1],
          dp2[R - 1][C - 1],
          dp3[R - 1][C - 1],
          )) print max(dp0[R - 1][C - 1],
          dp1[R - 1][C - 1],
          dp2[R - 1][C - 1],
          dp3[R - 1][C - 1],
          ) max dp0[R - 1][C - 1] [R - 1] dp0 R - 1 R 1 C - 1 C 1 dp1[R - 1][C - 1] [R - 1] dp1 R - 1 R 1 C - 1 C 1 dp2[R - 1][C - 1] [R - 1] dp2 R - 1 R 1 C - 1 C 1 dp3[R - 1][C - 1] [R - 1] dp3 R - 1 R 1 C - 1 C 1 enu = enumerate enumerate enu def mina(*argv, sub=1): return list(map(lambda x: x - sub, argv))
# 受け渡されたすべての要素からsubだけ引く.リストを*をつけて展開しておくこと def mina(*argv, sub=1): return list(map(lambda x: x - sub, argv))
# 受け渡されたすべての要素からsubだけ引く.リストを*をつけて展開しておくこと mina V = [[0] * C for _ in ra(R)] [[0] * C for _ in ra(R)] V def read_col(H):
    '''H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret))) def read_col(H):
    '''H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret))) read_col def read_tuple(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret def read_tuple(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret read_tuple C, K = ints() ints() C def ints(): return list(map(int, read().split())) def ints(): return list(map(int, read().split())) ints INF = 2**31 2**31 INF dp0 = [[0] * C for _ in ra(R)] [[0] * C for _ in ra(R)] dp0 ma = max(dp0[i - 1][j],
                 dp1[i - 1][j],
                 dp2[i - 1][j],
                 dp3[i - 1][j]) max(dp0[i - 1][j],
                 dp1[i - 1][j],
                 dp2[i - 1][j],
                 dp3[i - 1][j]) ma def a_int(): return int(read()) def a_int(): return int(read()) a_int R, C, K = ints() ints() R dp3 = [[0] * C for _ in ra(R)] [[0] * C for _ in ra(R)] dp3 def exit(*argv, **kwarg):
    print(*argv, **kwarg)
    sys.exit() def exit(*argv, **kwarg):
    print(*argv, **kwarg)
    sys.exit() exit K = ints() ints() K MOD = 10**9 + 7 10**9 + 7 MOD read = sys.stdin.readline sys.stdin.readline read dp1 = [[0] * C for _ in ra(R)] [[0] * C for _ in ra(R)] dp1 dp2 = [[0] * C for _ in ra(R)] [[0] * C for _ in ra(R)] dp2 RCV = read_tuple(K) read_tuple(K) RCV ra = range range ra
import sys

sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def exit(*argv, **kwarg):
    print(*argv, **kwarg)
    sys.exit()


def mina(*argv, sub=1): return list(map(lambda x: x - sub, argv))
# 受け渡されたすべての要素からsubだけ引く.リストを*をつけて展開しておくこと


def a_int(): return int(read())


def ints(): return list(map(int, read().split()))


def read_col(H):
    '''H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret)))


def read_tuple(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque


'''
dp[i][j]...(0,0)からスタートして(i,j)に到達する経路のなかでの最大の価値
dp[i][j]=max(dp[i][j-1],dp[i-1][j]) + v[i][j]


dp[i][j][k] ... (0,0)からスタートして(i,j)に到達する経路のなかでi行目ですでにk(以下)個選んでいるときの最大の価値

遷移は、i,jのvを拾うときと拾わないときのmax
dp[i][j][k] = max(dp[i][j-1][k-1]+V[i,j], dp[i][j-1][k]
                  ) #k個のままのほうが価値が高いかk-1から拾ったほうが価値が高いか

上からの遷移 # 拾うか拾わないかでこうかな
dp[i][j][0]=max(dp[i][j-1][0],max_k(dp[i-1][j]))
dp[i][j][1]=max(dp[i][j-1][0],max_k(dp[i-1][j][k])+V[i][j])
'''

R, C, K = ints()
RCV = read_tuple(K)
V = [[0] * C for _ in ra(R)]
for r, c, v in RCV:
    V[r - 1][c - 1] = v

# dp = [[[0] * 4 for _ in ra(C)] for _ in ra(R)]
dp0 = [[0] * C for _ in ra(R)]
dp1 = [[0] * C for _ in ra(R)]
dp2 = [[0] * C for _ in ra(R)]
dp3 = [[0] * C for _ in ra(R)]

# dp[0][0][0] = 0
dp1[0][0] = V[0][0]
dp2[0][0] = V[0][0]
dp3[0][0] = V[0][0]

for j in ra(1, C):
    dp1[0][j] = max(dp1[0][j - 1], dp0[0][j - 1] + V[0][j])
    dp2[0][j] = max(dp2[0][j - 1], dp1[0][j - 1] + V[0][j])
    dp3[0][j] = max(dp3[0][j - 1], dp2[0][j - 1] + V[0][j])

for i in ra(1, R):
    dp0[i][0] = dp1[i - 1][0]
    dp1[i][0] = dp0[i][0] + V[i][0]
    dp2[i][0] = dp0[i][0] + V[i][0]
    dp3[i][0] = dp0[i][0] + V[i][0]


for i in ra(1, R):
    for j in ra(1, C):
        ma = max(dp0[i - 1][j],
                 dp1[i - 1][j],
                 dp2[i - 1][j],
                 dp3[i - 1][j])

        dp0[i][j] = max(dp0[i][j - 1],  # 左
                        ma)  # 上

        dp1[i][j] = max(dp0[i][j - 1] + V[i][j],  # 左から来て拾う
                        dp1[i][j - 1],  # 拾わないほうが大きい場合もある
                        ma + V[i][j])  # 上から来て拾う

        dp2[i][j] = max(dp1[i][j - 1] + V[i][j], dp2[i][j - 1])
        dp3[i][j] = max(dp2[i][j - 1] + V[i][j], dp3[i][j - 1])


print(max(dp0[R - 1][C - 1],
          dp1[R - 1][C - 1],
          dp2[R - 1][C - 1],
          dp3[R - 1][C - 1],
          ))

# print(*values, sep='\n')
# print(*dp, sep='\n')

# dp2 = [[-1] * C for _ in ra(R)]
# for i in ra(R):
#     for j in ra(C):
#         dp2[i][j] = max(dp[i][j])
# print(*dp2, sep='\n')
