def solve():
  R, C, K = map(int, input().split())
  item = [[0]*C for _ in range(R)]
  for i in range(K):
    r,c,v = map(int, input().split())
    item[r-1][c-1] = v
  dp = [[[0]*(C+1) for _ in range(R+1)] for _ in range(4)]
  for i in range(1,R+1):
    for j in range(1,C+1):
      for k in range(4): #横から取らない
        dp[k][i][j] = dp[k][i][j-1]
      #上から取らない
      dp[0][i][j] = max(dp[0][i][j],dp[-1][i-1][j])
      if item[i-1][j-1]>0:
        #上からとる
        dp[1][i][j] = max(dp[1][i][j],dp[-1][i-1][j]+item[i-1][j-1])
        for k in range(1,4): #横から取る
          dp[k][i][j] = max(dp[k][i][j],dp[k-1][i][j-1]+item[i-1][j-1])
      for k in range(1,4):
        dp[k][i][j] = max(dp[k-1][i][j],dp[k][i][j])
  ans = 0
  for k in range(4):
    ans = max(ans,dp[k][-1][-1])
  return ans
print(solve()) def solve():
  R, C, K = map(int, input().split())
  item = [[0]*C for _ in range(R)]
  for i in range(K):
    r,c,v = map(int, input().split())
    item[r-1][c-1] = v
  dp = [[[0]*(C+1) for _ in range(R+1)] for _ in range(4)]
  for i in range(1,R+1):
    for j in range(1,C+1):
      for k in range(4): #横から取らない
        dp[k][i][j] = dp[k][i][j-1]
      #上から取らない
      dp[0][i][j] = max(dp[0][i][j],dp[-1][i-1][j])
      if item[i-1][j-1]>0:
        #上からとる
        dp[1][i][j] = max(dp[1][i][j],dp[-1][i-1][j]+item[i-1][j-1])
        for k in range(1,4): #横から取る
          dp[k][i][j] = max(dp[k][i][j],dp[k-1][i][j-1]+item[i-1][j-1])
      for k in range(1,4):
        dp[k][i][j] = max(dp[k-1][i][j],dp[k][i][j])
  ans = 0
  for k in range(4):
    ans = max(ans,dp[k][-1][-1])
  return ans solve R, C, K = map(int, input().split()) R map(int, input().split()) map int input().split() ().split () input split C K [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 i in range(K):
    r,c,v = map(int, input().split())
    item[r-1][c-1] = v
   i range(K) range K r,c,v = map(int, input().split()) r map(int, input().split()) map int input().split() ().split () input split 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]*(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)] dp = [[[0]*(C+1) for _ in range(R+1)] for _ in range(4)] dp [[[0]*(C+1) for _ in range(R+1)] for _ in range(4)] for i in range(1,R+1):
    for j in range(1,C+1):
      for k in range(4): #横から取らない
        dp[k][i][j] = dp[k][i][j-1]
      #上から取らない
      dp[0][i][j] = max(dp[0][i][j],dp[-1][i-1][j])
      if item[i-1][j-1]>0:
        #上からとる
        dp[1][i][j] = max(dp[1][i][j],dp[-1][i-1][j]+item[i-1][j-1])
        for k in range(1,4): #横から取る
          dp[k][i][j] = max(dp[k][i][j],dp[k-1][i][j-1]+item[i-1][j-1])
      for k in range(1,4):
        dp[k][i][j] = max(dp[k-1][i][j],dp[k][i][j])
   i range(1,R+1) range 1 R+1 R 1 for j in range(1,C+1):
      for k in range(4): #横から取らない
        dp[k][i][j] = dp[k][i][j-1]
      #上から取らない
      dp[0][i][j] = max(dp[0][i][j],dp[-1][i-1][j])
      if item[i-1][j-1]>0:
        #上からとる
        dp[1][i][j] = max(dp[1][i][j],dp[-1][i-1][j]+item[i-1][j-1])
        for k in range(1,4): #横から取る
          dp[k][i][j] = max(dp[k][i][j],dp[k-1][i][j-1]+item[i-1][j-1])
      for k in range(1,4):
        dp[k][i][j] = max(dp[k-1][i][j],dp[k][i][j])
   j range(1,C+1) range 1 C+1 C 1 for k in range(4): #横から取らない
        dp[k][i][j] = dp[k][i][j-1]
      #上から取らない
       k range(4) range 4 dp[k][i][j] = dp[k][i][j-1] dp[k][i][j] [i] [k] dp k i j dp[k][i][j-1] [i] [k] dp k i j-1 j 1 dp[0][i][j] = max(dp[0][i][j],dp[-1][i-1][j]) dp[0][i][j] [i] [0] dp 0 i j max(dp[0][i][j],dp[-1][i-1][j]) max dp[0][i][j] [i] [0] dp 0 i j dp[-1][i-1][j] [i-1] [-1] dp -1 i-1 i 1 j if item[i-1][j-1]>0:
        #上からとる
        dp[1][i][j] = max(dp[1][i][j],dp[-1][i-1][j]+item[i-1][j-1])
        for k in range(1,4): #横から取る
          dp[k][i][j] = max(dp[k][i][j],dp[k-1][i][j-1]+item[i-1][j-1])
       item[i-1][j-1]>0 item[i-1][j-1] [i-1] item i-1 i 1 j-1 j 1 0 dp[1][i][j] = max(dp[1][i][j],dp[-1][i-1][j]+item[i-1][j-1]) dp[1][i][j] [i] [1] dp 1 i j max(dp[1][i][j],dp[-1][i-1][j]+item[i-1][j-1]) max dp[1][i][j] [i] [1] dp 1 i j dp[-1][i-1][j]+item[i-1][j-1] dp[-1][i-1][j] [i-1] [-1] dp -1 i-1 i 1 j item[i-1][j-1] [i-1] item i-1 i 1 j-1 j 1 for k in range(1,4): #横から取る
          dp[k][i][j] = max(dp[k][i][j],dp[k-1][i][j-1]+item[i-1][j-1])
       k range(1,4) range 1 4 dp[k][i][j] = max(dp[k][i][j],dp[k-1][i][j-1]+item[i-1][j-1]) dp[k][i][j] [i] [k] dp k i j max(dp[k][i][j],dp[k-1][i][j-1]+item[i-1][j-1]) max dp[k][i][j] [i] [k] dp k i j dp[k-1][i][j-1]+item[i-1][j-1] dp[k-1][i][j-1] [i] [k-1] dp k-1 k 1 i j-1 j 1 item[i-1][j-1] [i-1] item i-1 i 1 j-1 j 1 for k in range(1,4):
        dp[k][i][j] = max(dp[k-1][i][j],dp[k][i][j])
   k range(1,4) range 1 4 dp[k][i][j] = max(dp[k-1][i][j],dp[k][i][j]) dp[k][i][j] [i] [k] dp k i j max(dp[k-1][i][j],dp[k][i][j]) max dp[k-1][i][j] [i] [k-1] dp k-1 k 1 i j dp[k][i][j] [i] [k] dp k i j ans = 0 ans 0 for k in range(4):
    ans = max(ans,dp[k][-1][-1])
   k range(4) range 4 ans = max(ans,dp[k][-1][-1]) ans max(ans,dp[k][-1][-1]) max ans dp[k][-1][-1] [-1] [k] dp k -1 -1 return ans ans print(solve()) print solve() solve def solve():
  R, C, K = map(int, input().split())
  item = [[0]*C for _ in range(R)]
  for i in range(K):
    r,c,v = map(int, input().split())
    item[r-1][c-1] = v
  dp = [[[0]*(C+1) for _ in range(R+1)] for _ in range(4)]
  for i in range(1,R+1):
    for j in range(1,C+1):
      for k in range(4): #横から取らない
        dp[k][i][j] = dp[k][i][j-1]
      #上から取らない
      dp[0][i][j] = max(dp[0][i][j],dp[-1][i-1][j])
      if item[i-1][j-1]>0:
        #上からとる
        dp[1][i][j] = max(dp[1][i][j],dp[-1][i-1][j]+item[i-1][j-1])
        for k in range(1,4): #横から取る
          dp[k][i][j] = max(dp[k][i][j],dp[k-1][i][j-1]+item[i-1][j-1])
      for k in range(1,4):
        dp[k][i][j] = max(dp[k-1][i][j],dp[k][i][j])
  ans = 0
  for k in range(4):
    ans = max(ans,dp[k][-1][-1])
  return ans def solve():
  R, C, K = map(int, input().split())
  item = [[0]*C for _ in range(R)]
  for i in range(K):
    r,c,v = map(int, input().split())
    item[r-1][c-1] = v
  dp = [[[0]*(C+1) for _ in range(R+1)] for _ in range(4)]
  for i in range(1,R+1):
    for j in range(1,C+1):
      for k in range(4): #横から取らない
        dp[k][i][j] = dp[k][i][j-1]
      #上から取らない
      dp[0][i][j] = max(dp[0][i][j],dp[-1][i-1][j])
      if item[i-1][j-1]>0:
        #上からとる
        dp[1][i][j] = max(dp[1][i][j],dp[-1][i-1][j]+item[i-1][j-1])
        for k in range(1,4): #横から取る
          dp[k][i][j] = max(dp[k][i][j],dp[k-1][i][j-1]+item[i-1][j-1])
      for k in range(1,4):
        dp[k][i][j] = max(dp[k-1][i][j],dp[k][i][j])
  ans = 0
  for k in range(4):
    ans = max(ans,dp[k][-1][-1])
  return ans solve
def solve():
  R, C, K = map(int, input().split())
  item = [[0]*C for _ in range(R)]
  for i in range(K):
    r,c,v = map(int, input().split())
    item[r-1][c-1] = v
  dp = [[[0]*(C+1) for _ in range(R+1)] for _ in range(4)]
  for i in range(1,R+1):
    for j in range(1,C+1):
      for k in range(4): #横から取らない
        dp[k][i][j] = dp[k][i][j-1]
      #上から取らない
      dp[0][i][j] = max(dp[0][i][j],dp[-1][i-1][j])
      if item[i-1][j-1]>0:
        #上からとる
        dp[1][i][j] = max(dp[1][i][j],dp[-1][i-1][j]+item[i-1][j-1])
        for k in range(1,4): #横から取る
          dp[k][i][j] = max(dp[k][i][j],dp[k-1][i][j-1]+item[i-1][j-1])
      for k in range(1,4):
        dp[k][i][j] = max(dp[k-1][i][j],dp[k][i][j])
  ans = 0
  for k in range(4):
    ans = max(ans,dp[k][-1][-1])
  return ans
print(solve())