#include<bits/stdc++.h>
 // #include <ext/pb_ds/tree_policy.hpp>
 // #include <ext/pb_ds/assoc_container.hpp>
 // #include<chrono>
  using namespace std;
  using namespace std::chrono;      
 // using namespace __gnu_pbds; 
 #define fastio     ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
 #define fi         first
 #define se         second
 #define int         long long 
 #define pb         push_back
 #define emp        emplace_back
 #define vv(x)      vector<x>
 #define mp(x,y)    map<x,y>
 #define dq(x)      deque<x>
 #define pql(x)     priority_queue<x>
 #define pqs(x)     priority_queue<x,vv(x),greater<x> >
 #define M          1000000007
 #define forf(i,a,b) for(int i=a;i<b;i++)
 #define it(x)      x::iterator
 #define ll         long long 
 #define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
 #define time__(d)  for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false); debug("%s time : %.4fs", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
 #define vii        vector<int>
 #define big        1e18
 #define sm         -1e9
 #define mkr        make_pair
 #define vpi        vector<pair<int,int> >
 #define pii        pair<int,int>
 #define rng        500005
 #define sz(x)      (int)x.size()
 #define rv(x)      reverse(x.begin(),x.end())
 #define out(x)     cout<<x.fi<<" "<<x.se<<endl;

 // typedef tree<pii, null_type, less<pii>, rb_tree_tag,  
 //            tree_order_statistics_node_update>  odst; 


void pr_init()
{
   
    #ifndef ONLINE_JUDGE
    freopen("gin.txt", "r", stdin);
   // freopen("output.txt", "w", stdout);
   
    #endif
}


vector<vii> mat ;
vector<vector<vii> >dp;

inline int maxi(int a,int b,int c,int d)
{
  return max(a,max(b,max(c,d)));
}
void solve()
{

    int r,c,k;
    cin >> r >> c >> k;
    
    mat.assign(r+1,vii(c+1,0));
    dp.assign(r+2,vector<vii>(c+2,vector<int>(4,INT_MIN)));
    

    forf(i,0,k)
    {
      int x,y,v;
      cin >> x >> y >> v;
      mat[x][y] = v;
    }

    for(int i=r;i>=1;i--)
    {
      for(int j=c;j>=1;j--)
      {
         if(i==r&&j==c)
         {
           dp[i][j][0] = 0;
           if(mat[i][j]!=0) dp[i][j][1] = mat[i][j];
           continue;
         }
         
           int dw = maxi(dp[i+1][j][0],dp[i+1][j][1],dp[i+1][j][2],dp[i+1][j][3]);
           dp[i][j][0] = max(dw,dp[i][j+1][0]);
          

         if(mat[i][j]==0)
         {
           
           dp[i][j][1] = dp[i][j+1][1];
           dp[i][j][2] = dp[i][j+1][2];
           dp[i][j][3] = dp[i][j+1][3];
         }else
         {
           dp[i][j][1] = max(dp[i][j+1][1] , max(dp[i][j+1][0]  + mat[i][j],dw+mat[i][j]));
           dp[i][j][2] = max(dp[i][j+1][2] , dp[i][j+1][1]+mat[i][j]);
           dp[i][j][3] = max(dp[i][j+1][3] , dp[i][j+1][2] + mat[i][j]);
         }
      }
    }

    
    int an = maxi(dp[1][1][0] , dp[1][1][1] , dp[1][1][2] , dp[1][1][3] );
    an = max(an , (int)0);

    cout<<an;
}

int32_t main()
{
  pr_init();
  fastio;
  auto start = high_resolution_clock::now(); 
  solve();
  auto stop = high_resolution_clock::now();
  auto duration = duration_cast<microseconds>(stop - start); 
  
    // cout << "Time taken by function: "
    //      << duration.count() << " microseconds" << endl; 

  return 0;
}

Measured memory_bytes: 707484