#include <bits/stdc++.h>
using namespace std;
using pii = pair<int,int>;
using pll = pair<long long, long long>;
const long long INF = 1<<29;

const int MOD = 1000000007;
long long ruizyou(long long m,long long n){
  if(m == 0)return 0;
  if(m == 1)return 1;
  long long ans = 1;
  long long tmp = m;
  for(int i=0;i<=30;i++){
    if(n & (1<<i)){
      ans *= tmp;
      ans %= MOD;
    }
    tmp *= tmp;
    tmp %= MOD;
  }
  return ans;
}
long long kaizyou(long long x){
  if(x == 0)return 1;
  return x * kaizyou(x-1) % MOD;
}
long long comb(long long x,long long y){
  long long bunsi = kaizyou(x);
  long long bunbo = kaizyou(x-y) * kaizyou(y) % MOD;
  return bunsi * ruizyou(bunbo,MOD-2) % MOD;
}
struct unionfind{
  vector<int> par;
  vector<int> hukasa;
  vector<int> kazu;
  unionfind(int n){
    par = vector<int>(n);
    hukasa = vector<int>(n,0);
    kazu = vector<int>(n,1);
    for(int i=0;i<n;i++){
      par.at(i) = i;
    }
  }
  int root(int x){
    if(par.at(x) == x)return x;
    return root(par.at(x));
  }
  void unite(int x,int y){
    int rx = root(x);
    int ry = root(y);
    if(rx == ry)return;
    if(hukasa.at(rx) >= hukasa.at(ry)){
      par.at(ry) = rx;
      hukasa.at(rx) = max(hukasa.at(ry) + 1,hukasa.at(rx));
      kazu.at(rx) += kazu.at(ry);
    }
    else{
      par.at(rx) = ry;
      kazu.at(ry) += kazu.at(rx);
    }
  }
  void newkazu(){
    int n = kazu.size();
    for(int i=0;i<n;i++){
      kazu.at(i) = kazu.at(root(i));
    }
  }
  bool same(int x,int y){
    return root(x) == root(y);
  }
};
int ctoi(char a){
  return a - '0';
}
long long gcd(long long a,long long b){
  long long c = max(a,b);
  long long d = min(a,b);
  if(d % c == 0)return c;
  return gcd(c,d%c);
}
long long lcm(long long a,long long b){
  return a * b / gcd(a,b);
}
int main(){
  int R,C,k;
  cin >> R >> C >> k;
  vector<int> r(k),c(k),v(k);
  for(int i=0;i<k;i++){
    cin >> r.at(i) >> c.at(i) >> v.at(i);
    //r.at(i)--;c.at(i)--;
  }
  vector<vector<int>> table(R+1,vector<int>(C+1,0));
  for(int i=0;i<k;i++)table.at(r.at(i)).at(c.at(i)) = v.at(i);
  vector<vector<vector<long long>>> dp(R+1,vector<vector<long long>>(C+1,vector<long long>(4,-1)));
  for(int i=0;i<=R;i++){
    for(int j=0;j<4;j++)dp.at(i).at(0).at(j) = 0;
  }
  for(int i=0;i<=C;i++){
    for(int j=0;j<4;j++)dp.at(0).at(i).at(j) = 0;
  }
  for(int i=1;i<=R;i++){
    for(int j=1;j<=C;j++){
      for(int k=0;k<4;k++){
        if(k==0){
          dp.at(i).at(j).at(k) = dp.at(i).at(j-1).at(0);
          dp.at(i).at(j).at(k) = max(dp.at(i).at(j).at(k),dp.at(i-1).at(j).at(0));
          dp.at(i).at(j).at(k) = max(dp.at(i).at(j).at(k),dp.at(i-1).at(j).at(1));
          dp.at(i).at(j).at(k) = max(dp.at(i).at(j).at(k),dp.at(i-1).at(j).at(2));
          dp.at(i).at(j).at(k) = max(dp.at(i).at(j).at(k),dp.at(i-1).at(j).at(3));
        }
        else{
          if(table.at(i).at(j)){
            if(dp.at(i).at(j-1).at(k-1) != -1){
              dp.at(i).at(j).at(k) = max(dp.at(i).at(j-1).at(k),dp.at(i).at(j-1).at(k-1) + table.at(i).at(j));
            }
            if(k == 1){
              dp.at(i).at(j).at(k) = max(dp.at(i).at(j).at(k),dp.at(i-1).at(j).at(0) + table.at(i).at(j));
              dp.at(i).at(j).at(k) = max(dp.at(i).at(j).at(k),dp.at(i-1).at(j).at(1) + table.at(i).at(j));
              dp.at(i).at(j).at(k) = max(dp.at(i).at(j).at(k),dp.at(i-1).at(j).at(2) + table.at(i).at(j));
              dp.at(i).at(j).at(k) = max(dp.at(i).at(j).at(k),dp.at(i-1).at(j).at(3) + table.at(i).at(j));
            }
          }
          else{
            if(dp.at(i).at(j-1).at(k) != -1){
              dp.at(i).at(j).at(k) = max(dp.at(i).at(j).at(k),dp.at(i).at(j-1).at(k));
            }
          }
        }
      }
    }
  }
  long long ans = 0;
  for(int i=0;i<4;i++){
    ans = max(ans,dp.at(R).at(C).at(i));
  }
  cout << ans << endl;
}

Measured memory_bytes: 674204