#include <bits/stdc++.h>
using namespace std;

#define rep(i,x,y) for(ll i=(x);i<(y);i++)
#define rrep(i,x,y) for(ll i=(ll)(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
#define itrout(x) for(int i=0;i<x.size();i++) {cout << x[i] << (i==x.size()-1 ? "\n" : " ");}
#ifdef LOCAL
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#define debugbit(x, n) cerr << #x << " = " << bitset<n>(x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#define itrdebug(x) cerr << #x << " "; for (auto & el : (x)) {cerr << (el) << " ";} cerr << endl
#define dassert(...) assert(__VA_ARGS__)
#else
#define debug(x)
#define debugbit(x, n)
#define itrdebug(x)
#define dassert(...)
#endif
//#define int long long

typedef long long ll;
const ll MOD = 1e9 + 7;
const long double EPS = 1e-8;

void solve(long long R, long long C, long long K, std::vector<long long> r, std::vector<long long> c, std::vector<long long> v){
    vector<vector<vector<ll>>> values(R+1, vector<vector<ll>>(C+1));
    rep(i,1,K+1) values[r[i]][c[i]].push_back(v[i]);
    rep(r,1,R+1) rep(c,1,C+1) sort(all(values[r][c]), greater<>());
    vector<vector<ll>> prevDp(4, vector<ll>(C+1));
    rep(r,1, R+1) {
        vector<vector<ll>> dp(4, vector<ll>(C+1));
        rep(c,1,C+1) {
            if (c>1) {
                if (values[r][c].size()>=3) {
                    dp[3][c] = max(dp[3][c], dp[0][c-1] + values[r][c][0] + values[r][c][1] + values[r][c][2]);
                }
                if (values[r][c].size()>=2) {
                    dp[3][c] = max(dp[3][c], dp[1][c-1] + values[r][c][0] + values[r][c][1]);
                    dp[2][c] = max(dp[2][c], dp[0][c-1] + values[r][c][0] + values[r][c][1]);
                }
                if (values[r][c].size()>=1) {
                    dp[3][c] = max(dp[3][c], dp[2][c-1] + values[r][c][0]);
                    dp[2][c] = max(dp[2][c], dp[1][c-1] + values[r][c][0]);
                    dp[1][c] = max(dp[1][c], dp[0][c-1] + values[r][c][0]);
                }
                dp[3][c] = max(dp[3][c], dp[3][c-1]);
                dp[2][c] = max(dp[2][c], dp[2][c-1]);
                dp[1][c] = max(dp[1][c], dp[1][c-1]);
                dp[0][c] = max(dp[0][c], dp[0][c-1]);
            }
            if (values[r][c].size()>=3) {
                dp[3][c] = max(dp[3][c], max(max(max(prevDp[0][c], prevDp[1][c]), prevDp[2][c]), prevDp[3][c]) + values[r][c][0] + values[r][c][1] + values[r][c][2]);
            }
            if (values[r][c].size()>=2) {
                dp[2][c] = max(dp[2][c], max(max(max(prevDp[0][c], prevDp[1][c]), prevDp[2][c]), prevDp[3][c]) + values[r][c][0] + values[r][c][1]);
            }
            if (values[r][c].size()>=1) {
                dp[1][c] = max(dp[1][c], max(max(max(prevDp[0][c], prevDp[1][c]), prevDp[2][c]), prevDp[3][c]) + values[r][c][0]);
            }
            dp[3][c] = max(dp[3][c], max(max(max(prevDp[0][c], prevDp[1][c]), prevDp[2][c]), prevDp[3][c]));
            dp[2][c] = max(dp[2][c], max(max(max(prevDp[0][c], prevDp[1][c]), prevDp[2][c]), prevDp[3][c]));
            dp[1][c] = max(dp[1][c], max(max(max(prevDp[0][c], prevDp[1][c]), prevDp[2][c]), prevDp[3][c]));
            dp[0][c] = max(dp[0][c], max(max(max(prevDp[0][c], prevDp[1][c]), prevDp[2][c]), prevDp[3][c]));
        }
        prevDp = dp;
    }
    cout << max(max(max(prevDp[0][C], prevDp[1][C]), prevDp[2][C]), prevDp[3][C]) << endl;
}

signed main(){
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    long long R;
    scanf("%lld",&R);
    long long C;
    scanf("%lld",&C);
    long long K;
    scanf("%lld",&K);
    std::vector<long long> r(K+1);
    std::vector<long long> c(K+1);
    std::vector<long long> v(K+1);
    for(int i = 0 ; i < K ; i++){
        scanf("%lld",&r[i+1]);
        scanf("%lld",&c[i+1]);
        scanf("%lld",&v[i+1]);
    }
    solve(R, C, K, std::move(r), std::move(c), std::move(v));
    return 0;
}


Measured memory_bytes: 225728