#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using vi=vector<int>;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
#define chmax(x,y) x = max(x,y)

int a[3005][3005];
ll dp[3005][3005][4];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int R,C,n;
    cin >> R >> C >> n;
    rep(i,n){
        int r,c,v;
        cin >> r >> c >> v;
        a[r-1][c-1]=v;
    }

    rep(i,R)rep(j,C){
        for(int k=2;k>=0;--k){
            chmax(dp[i][j][k+1],dp[i][j][k]+a[i][j]);
        }
        rep(k,4){
            chmax(dp[i+1][j][0],dp[i][j][k]);
            chmax(dp[i][j+1][k],dp[i][j][k]);
        }
    }
    ll ans=0;
    rep(k,4) chmax(ans,dp[R-1][C-1][k]);
    cout << ans << "\n";
    return 0;
}   