import sys,collections as cl,bisect as bs,heapq as hq
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    if len(x) == 0:
        return []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

def pow_k(x, n):
    ans = 1
    while n:
        if n % 2:
            ans *= x
        x *= x
        n >>= 1
    return ans

"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

r,c,k = m()


item = [[0 for j in range(c)] for i in range(r)]



for i in range(k):
    R,C,V = m()
    item[R-1][C-1] = V


dp = [[0 for k in range(4)] for j in range(c)]
dpo = [[0 for k in range(4)] for j in range(c)]
for i in range(r):
    for j in range(c):
        if j == 0:
            if item[i][j] != 0:
                po = 0
                for kk in range(4):
                    po = max(po,dpo[j][kk])
                for k in range(4):
                    if k == 0:
                        dp[j][k] = po
                    elif k == 1:
                        dp[j][k] = po + item[i][j]
                    else:
                        dp[j][k] = 0

            else:
                po = 0
                for kk in range(4):
                    po = max(po,dpo[j][kk])
                for k in range(4):
                    if k == 0:
                        dp[j][k] = po
                    else:
                        dp[j][k] = 0

        else:
            if item[i][j] != 0:
                po = 0
                for kk in range(4):
                    po = max(po,dpo[j][kk])
                for k in range(4):
                    if k == 0:
                        dp[j][k] = max(dp[j-1][k],po)
                    elif k == 1:
                        dp[j][k] = max(dp[j-1][k],dp[j-1][0] + item[i][j],po + item[i][j])
                    else:
                        dp[j][k] = max(dp[j-1][k],dp[j-1][k-1] + item[i][j])

            else:
                po = 0
                for kk in range(4):
                    po = max(po,dpo[j][kk])
                for k in range(4):
                    if k == 0:
                        dp[j][k] = max(dp[j-1][k],po)
                    else:
                        dp[j][k] = dp[j-1][k]
    for j in range(c):
        for k in range(4):
            dpo[j][k] = dp[j][k]
            dp[j][k] = 0


ans = 0

for i in range(4):
    ans = max(ans,dpo[-1][i])
print(ans) import sys,collections as cl,bisect as bs,heapq as hq sys collections bisect heapq sys.setrecursionlimit(100000) sys.setrecursionlimit sys setrecursionlimit 100000 input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline mod = 10**9+7 mod 10**9+7 10**9 10 9 7 Max = sys.maxsize Max sys.maxsize sys maxsize def l(): #intのlist
    return list(map(int,input().split())) l return list(map(int,input().split())) list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split def m(): #複数文字
    return map(int,input().split()) m return map(int,input().split()) map(int,input().split()) map int input().split() ().split () input split def onem(): #Nとかの取得
    return int(input()) onem return int(input()) int(input()) int input() input def s(x): #圧縮
    a = []
    if len(x) == 0:
        return []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a s a = [] a [] if len(x) == 0:
        return []
     len(x) == 0 len(x) len x 0 return [] [] aa = x[0] aa x[0] x 0 su = 1 su 1 for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
     i range(len(x)-1) range len(x)-1 len(x) len x 1 if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
     aa != x[i+1] aa x[i+1] x i+1 i 1 a.append([aa,su]) a.append a append [aa,su] aa su aa = x[i+1] aa x[i+1] x i+1 i 1 su = 1 su 1 su += 1 su 1 a.append([aa,su]) a.append a append [aa,su] aa su return a a x x def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x)) jo return " ".join(map(str,x)) " ".join(map(str,x)) " ".join " " join map(str,x) map str x x x def max2(x): #他のときもどうように作成可能
    return max(map(max,x)) max2 return max(map(max,x)) max(map(max,x)) max map(max,x) map max x x x def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False In k = bs.bisect_left(a,x) k bs.bisect_left(a,x) bs.bisect_left bs bisect_left a x if k != len(a) and a[k] ==  x:
        return True
    else:
        return False k != len(a) and a[k] ==  x k != len(a) k len(a) len a a[k] ==  x a[k] a k x return True True return False False x x a a def pow_k(x, n):
    ans = 1
    while n:
        if n % 2:
            ans *= x
        x *= x
        n >>= 1
    return ans pow_k ans = 1 ans 1 while n:
        if n % 2:
            ans *= x
        x *= x
        n >>= 1
     n if n % 2:
            ans *= x
         n % 2 n 2 ans *= x ans x x *= x x x n >>= 1 n 1 return ans ans x x n n """
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
""" r,c,k = m() r m() m c k [0 for j in range(c)] for i in range(r) for i in range(r) i range(r) range r for i in range(r) [0 for j in range(c)] item = [[0 for j in range(c)] for i in range(r)] item [[0 for j in range(c)] for i in range(r)] for i in range(k):
    R,C,V = m()
    item[R-1][C-1] = V i range(k) range k R,C,V = m() R m() m C V item[R-1][C-1] = V item[R-1][C-1] [R-1] item R-1 R 1 C-1 C 1 V [0 for k in range(4)] for j in range(c) for j in range(c) j range(c) range c for j in range(c) [0 for k in range(4)] dp = [[0 for k in range(4)] for j in range(c)] dp [[0 for k in range(4)] for j in range(c)] [0 for k in range(4)] for j in range(c) for j in range(c) j range(c) range c for j in range(c) [0 for k in range(4)] dpo = [[0 for k in range(4)] for j in range(c)] dpo [[0 for k in range(4)] for j in range(c)] for i in range(r):
    for j in range(c):
        if j == 0:
            if item[i][j] != 0:
                po = 0
                for kk in range(4):
                    po = max(po,dpo[j][kk])
                for k in range(4):
                    if k == 0:
                        dp[j][k] = po
                    elif k == 1:
                        dp[j][k] = po + item[i][j]
                    else:
                        dp[j][k] = 0

            else:
                po = 0
                for kk in range(4):
                    po = max(po,dpo[j][kk])
                for k in range(4):
                    if k == 0:
                        dp[j][k] = po
                    else:
                        dp[j][k] = 0

        else:
            if item[i][j] != 0:
                po = 0
                for kk in range(4):
                    po = max(po,dpo[j][kk])
                for k in range(4):
                    if k == 0:
                        dp[j][k] = max(dp[j-1][k],po)
                    elif k == 1:
                        dp[j][k] = max(dp[j-1][k],dp[j-1][0] + item[i][j],po + item[i][j])
                    else:
                        dp[j][k] = max(dp[j-1][k],dp[j-1][k-1] + item[i][j])

            else:
                po = 0
                for kk in range(4):
                    po = max(po,dpo[j][kk])
                for k in range(4):
                    if k == 0:
                        dp[j][k] = max(dp[j-1][k],po)
                    else:
                        dp[j][k] = dp[j-1][k]
    for j in range(c):
        for k in range(4):
            dpo[j][k] = dp[j][k]
            dp[j][k] = 0 i range(r) range r for j in range(c):
        if j == 0:
            if item[i][j] != 0:
                po = 0
                for kk in range(4):
                    po = max(po,dpo[j][kk])
                for k in range(4):
                    if k == 0:
                        dp[j][k] = po
                    elif k == 1:
                        dp[j][k] = po + item[i][j]
                    else:
                        dp[j][k] = 0

            else:
                po = 0
                for kk in range(4):
                    po = max(po,dpo[j][kk])
                for k in range(4):
                    if k == 0:
                        dp[j][k] = po
                    else:
                        dp[j][k] = 0

        else:
            if item[i][j] != 0:
                po = 0
                for kk in range(4):
                    po = max(po,dpo[j][kk])
                for k in range(4):
                    if k == 0:
                        dp[j][k] = max(dp[j-1][k],po)
                    elif k == 1:
                        dp[j][k] = max(dp[j-1][k],dp[j-1][0] + item[i][j],po + item[i][j])
                    else:
                        dp[j][k] = max(dp[j-1][k],dp[j-1][k-1] + item[i][j])

            else:
                po = 0
                for kk in range(4):
                    po = max(po,dpo[j][kk])
                for k in range(4):
                    if k == 0:
                        dp[j][k] = max(dp[j-1][k],po)
                    else:
                        dp[j][k] = dp[j-1][k]
     j range(c) range c if j == 0:
            if item[i][j] != 0:
                po = 0
                for kk in range(4):
                    po = max(po,dpo[j][kk])
                for k in range(4):
                    if k == 0:
                        dp[j][k] = po
                    elif k == 1:
                        dp[j][k] = po + item[i][j]
                    else:
                        dp[j][k] = 0

            else:
                po = 0
                for kk in range(4):
                    po = max(po,dpo[j][kk])
                for k in range(4):
                    if k == 0:
                        dp[j][k] = po
                    else:
                        dp[j][k] = 0

        else:
            if item[i][j] != 0:
                po = 0
                for kk in range(4):
                    po = max(po,dpo[j][kk])
                for k in range(4):
                    if k == 0:
                        dp[j][k] = max(dp[j-1][k],po)
                    elif k == 1:
                        dp[j][k] = max(dp[j-1][k],dp[j-1][0] + item[i][j],po + item[i][j])
                    else:
                        dp[j][k] = max(dp[j-1][k],dp[j-1][k-1] + item[i][j])

            else:
                po = 0
                for kk in range(4):
                    po = max(po,dpo[j][kk])
                for k in range(4):
                    if k == 0:
                        dp[j][k] = max(dp[j-1][k],po)
                    else:
                        dp[j][k] = dp[j-1][k]
     j == 0 j 0 if item[i][j] != 0:
                po = 0
                for kk in range(4):
                    po = max(po,dpo[j][kk])
                for k in range(4):
                    if k == 0:
                        dp[j][k] = po
                    elif k == 1:
                        dp[j][k] = po + item[i][j]
                    else:
                        dp[j][k] = 0

            else:
                po = 0
                for kk in range(4):
                    po = max(po,dpo[j][kk])
                for k in range(4):
                    if k == 0:
                        dp[j][k] = po
                    else:
                        dp[j][k] = 0

         item[i][j] != 0 item[i][j] [i] item i j 0 po = 0 po 0 for kk in range(4):
                    po = max(po,dpo[j][kk])
                 kk range(4) range 4 po = max(po,dpo[j][kk]) po max(po,dpo[j][kk]) max po dpo[j][kk] [j] dpo j kk for k in range(4):
                    if k == 0:
                        dp[j][k] = po
                    elif k == 1:
                        dp[j][k] = po + item[i][j]
                    else:
                        dp[j][k] = 0

             k range(4) range 4 if k == 0:
                        dp[j][k] = po
                    elif k == 1:
                        dp[j][k] = po + item[i][j]
                    else:
                        dp[j][k] = 0

             k == 0 k 0 dp[j][k] = po dp[j][k] [j] dp j k po elif k == 1:
                        dp[j][k] = po + item[i][j]
                     k == 1 k 1 dp[j][k] = po + item[i][j] dp[j][k] [j] dp j k po + item[i][j] po item[i][j] [i] item i j dp[j][k] = 0 dp[j][k] [j] dp j k 0 po = 0 po 0 for kk in range(4):
                    po = max(po,dpo[j][kk])
                 kk range(4) range 4 po = max(po,dpo[j][kk]) po max(po,dpo[j][kk]) max po dpo[j][kk] [j] dpo j kk for k in range(4):
                    if k == 0:
                        dp[j][k] = po
                    else:
                        dp[j][k] = 0

         k range(4) range 4 if k == 0:
                        dp[j][k] = po
                    else:
                        dp[j][k] = 0

         k == 0 k 0 dp[j][k] = po dp[j][k] [j] dp j k po dp[j][k] = 0 dp[j][k] [j] dp j k 0 if item[i][j] != 0:
                po = 0
                for kk in range(4):
                    po = max(po,dpo[j][kk])
                for k in range(4):
                    if k == 0:
                        dp[j][k] = max(dp[j-1][k],po)
                    elif k == 1:
                        dp[j][k] = max(dp[j-1][k],dp[j-1][0] + item[i][j],po + item[i][j])
                    else:
                        dp[j][k] = max(dp[j-1][k],dp[j-1][k-1] + item[i][j])

            else:
                po = 0
                for kk in range(4):
                    po = max(po,dpo[j][kk])
                for k in range(4):
                    if k == 0:
                        dp[j][k] = max(dp[j-1][k],po)
                    else:
                        dp[j][k] = dp[j-1][k]
     item[i][j] != 0 item[i][j] [i] item i j 0 po = 0 po 0 for kk in range(4):
                    po = max(po,dpo[j][kk])
                 kk range(4) range 4 po = max(po,dpo[j][kk]) po max(po,dpo[j][kk]) max po dpo[j][kk] [j] dpo j kk for k in range(4):
                    if k == 0:
                        dp[j][k] = max(dp[j-1][k],po)
                    elif k == 1:
                        dp[j][k] = max(dp[j-1][k],dp[j-1][0] + item[i][j],po + item[i][j])
                    else:
                        dp[j][k] = max(dp[j-1][k],dp[j-1][k-1] + item[i][j])

             k range(4) range 4 if k == 0:
                        dp[j][k] = max(dp[j-1][k],po)
                    elif k == 1:
                        dp[j][k] = max(dp[j-1][k],dp[j-1][0] + item[i][j],po + item[i][j])
                    else:
                        dp[j][k] = max(dp[j-1][k],dp[j-1][k-1] + item[i][j])

             k == 0 k 0 dp[j][k] = max(dp[j-1][k],po) dp[j][k] [j] dp j k max(dp[j-1][k],po) max dp[j-1][k] [j-1] dp j-1 j 1 k po elif k == 1:
                        dp[j][k] = max(dp[j-1][k],dp[j-1][0] + item[i][j],po + item[i][j])
                     k == 1 k 1 dp[j][k] = max(dp[j-1][k],dp[j-1][0] + item[i][j],po + item[i][j]) dp[j][k] [j] dp j k max(dp[j-1][k],dp[j-1][0] + item[i][j],po + item[i][j]) max dp[j-1][k] [j-1] dp j-1 j 1 k dp[j-1][0] + item[i][j] dp[j-1][0] [j-1] dp j-1 j 1 0 item[i][j] [i] item i j po + item[i][j] po item[i][j] [i] item i j dp[j][k] = max(dp[j-1][k],dp[j-1][k-1] + item[i][j]) dp[j][k] [j] dp j k max(dp[j-1][k],dp[j-1][k-1] + item[i][j]) max dp[j-1][k] [j-1] dp j-1 j 1 k dp[j-1][k-1] + item[i][j] dp[j-1][k-1] [j-1] dp j-1 j 1 k-1 k 1 item[i][j] [i] item i j po = 0 po 0 for kk in range(4):
                    po = max(po,dpo[j][kk])
                 kk range(4) range 4 po = max(po,dpo[j][kk]) po max(po,dpo[j][kk]) max po dpo[j][kk] [j] dpo j kk for k in range(4):
                    if k == 0:
                        dp[j][k] = max(dp[j-1][k],po)
                    else:
                        dp[j][k] = dp[j-1][k]
     k range(4) range 4 if k == 0:
                        dp[j][k] = max(dp[j-1][k],po)
                    else:
                        dp[j][k] = dp[j-1][k]
     k == 0 k 0 dp[j][k] = max(dp[j-1][k],po) dp[j][k] [j] dp j k max(dp[j-1][k],po) max dp[j-1][k] [j-1] dp j-1 j 1 k po dp[j][k] = dp[j-1][k] dp[j][k] [j] dp j k dp[j-1][k] [j-1] dp j-1 j 1 k for j in range(c):
        for k in range(4):
            dpo[j][k] = dp[j][k]
            dp[j][k] = 0 j range(c) range c for k in range(4):
            dpo[j][k] = dp[j][k]
            dp[j][k] = 0 k range(4) range 4 dpo[j][k] = dp[j][k] dpo[j][k] [j] dpo j k dp[j][k] [j] dp j k dp[j][k] = 0 dp[j][k] [j] dp j k 0 ans = 0 ans 0 for i in range(4):
    ans = max(ans,dpo[-1][i]) i range(4) range 4 ans = max(ans,dpo[-1][i]) ans max(ans,dpo[-1][i]) max ans dpo[-1][i] [-1] dpo -1 i print(ans) print ans po = 0 0 po po = 0 0 po Max = sys.maxsize sys.maxsize Max def m(): #複数文字
    return map(int,input().split()) def m(): #複数文字
    return map(int,input().split()) m def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False In po = 0 0 po ans = 0 0 ans def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x)) def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x)) jo def max2(x): #他のときもどうように作成可能
    return max(map(max,x)) def max2(x): #他のときもどうように作成可能
    return max(map(max,x)) max2 V = m() m() V r,c,k = m() m() r input = sys.stdin.readline sys.stdin.readline input po = max(po,dpo[j][kk]) max(po,dpo[j][kk]) po mod = 10**9+7 10**9+7 mod def s(x): #圧縮
    a = []
    if len(x) == 0:
        return []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a def s(x): #圧縮
    a = []
    if len(x) == 0:
        return []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a s dpo = [[0 for k in range(4)] for j in range(c)] [[0 for k in range(4)] for j in range(c)] dpo po = max(po,dpo[j][kk]) max(po,dpo[j][kk]) po dp = [[0 for k in range(4)] for j in range(c)] [[0 for k in range(4)] for j in range(c)] dp C,V = m() m() C po = max(po,dpo[j][kk]) max(po,dpo[j][kk]) po k = m() m() k def l(): #intのlist
    return list(map(int,input().split())) def l(): #intのlist
    return list(map(int,input().split())) l def onem(): #Nとかの取得
    return int(input()) def onem(): #Nとかの取得
    return int(input()) onem def pow_k(x, n):
    ans = 1
    while n:
        if n % 2:
            ans *= x
        x *= x
        n >>= 1
    return ans def pow_k(x, n):
    ans = 1
    while n:
        if n % 2:
            ans *= x
        x *= x
        n >>= 1
    return ans pow_k po = max(po,dpo[j][kk]) max(po,dpo[j][kk]) po c,k = m() m() c R,C,V = m() m() R po = 0 0 po item = [[0 for j in range(c)] for i in range(r)] [[0 for j in range(c)] for i in range(r)] item ans = max(ans,dpo[-1][i]) max(ans,dpo[-1][i]) ans
import sys,collections as cl,bisect as bs,heapq as hq
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    if len(x) == 0:
        return []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

def pow_k(x, n):
    ans = 1
    while n:
        if n % 2:
            ans *= x
        x *= x
        n >>= 1
    return ans

"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

r,c,k = m()


item = [[0 for j in range(c)] for i in range(r)]



for i in range(k):
    R,C,V = m()
    item[R-1][C-1] = V


dp = [[0 for k in range(4)] for j in range(c)]
dpo = [[0 for k in range(4)] for j in range(c)]
for i in range(r):
    for j in range(c):
        if j == 0:
            if item[i][j] != 0:
                po = 0
                for kk in range(4):
                    po = max(po,dpo[j][kk])
                for k in range(4):
                    if k == 0:
                        dp[j][k] = po
                    elif k == 1:
                        dp[j][k] = po + item[i][j]
                    else:
                        dp[j][k] = 0

            else:
                po = 0
                for kk in range(4):
                    po = max(po,dpo[j][kk])
                for k in range(4):
                    if k == 0:
                        dp[j][k] = po
                    else:
                        dp[j][k] = 0

        else:
            if item[i][j] != 0:
                po = 0
                for kk in range(4):
                    po = max(po,dpo[j][kk])
                for k in range(4):
                    if k == 0:
                        dp[j][k] = max(dp[j-1][k],po)
                    elif k == 1:
                        dp[j][k] = max(dp[j-1][k],dp[j-1][0] + item[i][j],po + item[i][j])
                    else:
                        dp[j][k] = max(dp[j-1][k],dp[j-1][k-1] + item[i][j])

            else:
                po = 0
                for kk in range(4):
                    po = max(po,dpo[j][kk])
                for k in range(4):
                    if k == 0:
                        dp[j][k] = max(dp[j-1][k],po)
                    else:
                        dp[j][k] = dp[j-1][k]
    for j in range(c):
        for k in range(4):
            dpo[j][k] = dp[j][k]
            dp[j][k] = 0


ans = 0

for i in range(4):
    ans = max(ans,dpo[-1][i])
print(ans)
