/*
Written By mafailure
*/
//In the name of God
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file 
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional> // for less
using namespace std;
using namespace __gnu_pbds;
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl "\n"
#define int long long 
// int dx[]={-1,1,0,0}; int dy[]={0,0,1,-1};
// int dx[]={2,2,-2,-2,1,1,-1,-1}; int dy[]={1,-1,1,-1,2,-2,2,-2};
const long long mod = 1e9 + 7;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> ii;
typedef vector< pair< int, int > > vii;
typedef map<int, int> mii;
typedef pair<int, ii> pip;
typedef pair<ii, int> ppi;
#define arrinp(arr,init,final,size,type) type* arr=new type[size];for(int i=init;i<final;i++)cin>>arr[i];
#define cr2d(arr,n,m,t) t**arr=new t*[n];for(int i=0;i<n;i++)arr[i]=new t[m];
#define w(t) int t;cin>>t; while(t--)
#define takeInp(n) int n;cin>>n;
#define fr(i,init,final) for(int i=init;i<final;i++)
#define frr(i,init,final) for(int i=init;i>=final;i--)
#define Fr(i,final) for(int i=0;i<final;i++)
#define Frr(i,first) for(int i=first;i>=0;i--)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define debug(x) cerr<<">value ("<<#x<<") : "<<x<<endl;
#define setb __builtin_popcount
#define lsone(n) (n&(-n))
#define rlsone(n) (n&(n-1))

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>  nds; 
vi init(string s)
{
	istringstream sin(s);
	int n;
	vi arr;
	while(sin>>n)arr.push_back(n);
	return arr;
}
int power(int x, int y)
{ 
	if(y==0)return 1;
	int u=power(x,y/2);
	u=(u*u)%mod;
	if(y%2)u=(x*u)%mod;
	return u;
    
}
int gcd(int a,int b)
{
	if(a<b)return gcd(b,a);
	return (b==0?a:(a%b?gcd(b,a%b):b));
}
int gcd_e(int a,int b,int &x,int &y)
{
	
	if(b==0){x=1; y=0; return a;}
	int x1,y1;
	int p=gcd_e(b,a%b,x1,y1);
	x=y1;
	y=x1-(a/b)*y1;
	return p;
}
int dp[3002][3002][4];
int arr[3002][3002];

int r,c,xx;
void solve()
{
	memset(dp,0LL,sizeof(dp));
	frr(i,r,0)
	{
		frr(j,c,0)
		{
			fr(k,0,4)
				{  int &a =dp[i][j][k];
					if(arr[i][j]==-1){  a=max({dp[i][j+1][k],dp[i+1][j][3]});}
					else 
					{
								a=max({dp[i][j+1][k],dp[i+1][j][3]});
								if(k!=0)a=max({a,dp[i][j+1][k-1]+arr[i][j],dp[i+1][j][3]+arr[i][j]});
					}
				}
	}
}
	cout<<dp[0][0][3]<<endl;//cout<<dp[0][1][2]<<endl<<dp[0][1][3]<<endl<<dp[0][3][1]<<endl<<dp[0][3][0];
}
/*
void solve()
{
	 fr(i,0,4)fr(j,0,2)dp[r+1][c][i][j]=dp[r][c+1][i][j]=0 ;
	 fr(i,r+1,3001)fr(j,0,3001)fr(k,0,4)fr(r,0,2)dp[i][j][k][r]=0;
	 fr(i,0,3001)fr(j,c+1,3001)fr(k,0,4)fr(r,0,2)dp[i][j][k][r]=0;
	 frr(i,r,0)frr(j,c,0)fr(k,0,4)
	 {
	 	//cout<<i<<" "<<j<<" "<<k<<" ";
	 	 if(arr[i][j]==-1)dp[i][j][k][0]=dp[i][j][k][1]=max({dp[i+1][j][3][1],dp[i+1][j][3][0],dp[i][j+1][k][1],dp[i][j+1][k][0]});
	 	 else 
	 	 {   
	 	 		dp[i][j][k][1]=max({dp[i+1][j][3][0],dp[i+1][j][3][1],dp[i][j+1][k][0],dp[i][j+1][k][1],dp[i+1][j][3][0]+arr[i][j],dp[i+1][j][3][1]+arr[i][j]});
	 	     if(k)dp[i][j][k][1]=max({dp[i][j][k][1],max(dp[i][j+1][k-1][0]+arr[i][j],dp[i][j+1][k-1][1]+arr[i][j])}),
	 	 		 dp[i][j][k][0]=max({dp[i+1][j][3][0],dp[i+1][j][3][1],dp[i][j+1][k][0],dp[i][j+1][k][1]}) ;
	 	  }
	 	 //cout<<dp[i][j][k]<<endl;
	 }
	 cout<<max(dp[0][0][3][0],dp[0][0][3][1])<<endl;
}  */
signed main()
{
	IOS
	
	cin>>r>>c>>xx;
	r--;c--;
	//memset(arr,-1,sizeof(arr));
	fr(i,0,3001)fr(j,0,3001)arr[i][j]=-1;
	fr(i,0,xx)
	{
		int x,y,v;
		cin>>x>>y>>v;
		x--; y--;
		arr[x][y]=v;
	}
	//fr(i,0,r+1){fr(j,0,c+1)cout<<arr[i][j]<<" "; cout<<endl;}
	solve();
	
	
	
	
	
}



Measured memory_bytes: 355676