// Template begins
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <stdio.h>
#include <math.h>
#include <iomanip>
#include <queue> 
#include <string.h>
#include <string>
using namespace std;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define endl "\n"
#define lb lower_bound
#define ub upper_bound
#define fo(i,a,b) for(i=a;i<b;i++)
#define all(v) (v).begin(),(v).end()
#define sort0(v) sort(all(v))
#define lbb(a,b,arr,x) lower_bound(arr+a,arr+b+1,x)-arr
#define ubb(a,b,arr,x) upper_bound(arr+a,arr+b+1,x)-arr
#define freq(a,b,arr,x) upper_bound(arr+a,arr+b+1,x)-lower_bound(arr+a,arr+b+1,x)
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define d0(x) cout<<(x)<<" "
#define d1(x) cout<<(x)<<endl
#define d2(x,y) cout<<(x)<<" "<<(y)<<endl
#define d3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define d4(a,b,c,d) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<endl
#define d5(a,b,c,d,e) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<" "<<(e)<<endl
#define d6(a,b,c,d,e,f) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<" "<<(e)<<" "<<(f)<<endl
#define max3(a,b,c) max(max((a),(b)),(c))
#define max4(a,b,c,d) max(max((a),(b)),max((c),(d)))
#define ss second
#define ff first
#define pb push_back
#define mp make_pair
#define printp(x) cout << x.ff << " " << x.ss << endl

const ll mod=998244353;
#define inf 9999999999999
#define MAXN   100001 
  
// stores smallest prime factor for every number 
ll inv(ll i){if(i==1) return 1;return (mod-((mod/i)*inv(mod%i))%mod)%mod;}
ll gcd(ll a,ll b){if(a==0) return b;return gcd(b,b%a);}
inline void fastio(){ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);}
// Template ends
const int MN = 2e5+7;
int r,c,k;
ll grid[3001][3001];
ll dp[3001][3001][4];
ll solve(ll grid[3001][3001], int a, int b, int picked){
    if(a<=0 || b<=0){
        return 0;
    }
    ll ans;
    if(dp[a][b][picked]!=-1){
        return dp[a][b][picked];
    }
    //cout<<grid[a-1][b-1]<<endl;
    if(picked<3){
        ans=max(solve(grid,a-1,b,0), solve(grid,a,b-1,picked));
        if(grid[a-1][b-1]>0)
            ans=max(ans,max(solve(grid,a-1,b,0) + grid[a-1][b-1] , solve(grid,a,b-1,picked+1) + grid[a-1][b-1]));
    }else{
        ans=max(solve(grid,a-1,b,0), solve(grid,a,b-1,picked));
    }
    dp[a][b][picked]=ans;
    return dp[a][b][picked];
}



int main(){
    fastio();    
        //write code here
            cin>>r>>c>>k;
            for(int i=0;i<r;i++){
                for(int j=0;j<c;j++){
                    grid[i][j]=0;
                }
            }
            for(int i=0;i<=r;i++){
                for(int j=0;j<=c;j++){
                    for(int k=0;k<4;k++){
                        dp[i][j][k]=-1;
                    }
                }
            }
            while(k--){
                int a,b; cin>>a>>b;
                ll v; cin>>v;
                grid[a-1][b-1]=v;
            }
            /*for(int i=0;i<r;i++){
                for(int j=0;j<c;j++){
                    cout<<grid[i][j]<<" ";
                }
                cout<<endl;
            }*/

            ll res=solve(grid, r, c, 0);
            cout<<res<<endl;


            
    return 0;
}

 

Measured memory_bytes: 355324