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

long long vs[3000 + 1][3000 + 1] = {};
long long dp[3000+1][3000+1][3+1];

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){
    // map<long long, map<long long, long long>> vs;
    // long long vs[R + 1][C + 1] = {};
    for (int i = 0; i < K; i++) {
        vs[r[i]][c[i]] = v[i];
    }
    // long long dp[R+1][C+1][3+1] = {};  // (r, c) まで見た時に各行で n 個取った時の最大価値
    for (int i = 1; i <= R; i++) {
        for (int j = 0; j <= C; j++) {
            for (int k = 0; k <= 3; k++) {
                if (j > 0) {
                    if (k == 0) {
                        dp[i][j][k] = max({
                            dp[i][j-1][k],              // not take
                            dp[i-1][j][0],              // not take
                            dp[i-1][j][1],              // not take
                            dp[i-1][j][2],              // not take
                            dp[i-1][j][3]              // not take
                        });
                    } else if (k == 1) {
                        dp[i][j][k] = max({
                            dp[i][j-1][k],              // not take
                            dp[i][j-1][k-1] + vs[i][j],  // take
                            dp[i-1][j][0] + vs[i][j],  // take
                            dp[i-1][j][1] + vs[i][j],  // take
                            dp[i-1][j][2] + vs[i][j],  // take
                            dp[i-1][j][3] + vs[i][j]  // take
                        });
                    } else {
                        dp[i][j][k] = max(
                            dp[i][j-1][k],              // not take
                            dp[i][j-1][k-1] + vs[i][j]  // take
                        );
                    }
                } else {
                    if (k == 0) {
                        dp[i][j][k] = max({
                            dp[i-1][j][0],              // not take
                            dp[i-1][j][1],              // not take
                            dp[i-1][j][2],              // not take
                            dp[i-1][j][3]              // not take
                        });
                    } else if (k == 1) {
                        dp[i][j][k] = max({
                            dp[i-1][j][0] + vs[i][j],  // take
                            dp[i-1][j][1] + vs[i][j],  // take
                            dp[i-1][j][2] + vs[i][j],  // take
                            dp[i-1][j][3] + vs[i][j]  // take
                        });
                    }
                }
            }
        }
    }
    cout << max({dp[R][C][0], dp[R][C][1], dp[R][C][2], dp[R][C][3]}) << endl;
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long R;
    scanf("%lld",&R);
    long long C;
    scanf("%lld",&C);
    long long K;
    scanf("%lld",&K);
    std::vector<long long> r(K);
    std::vector<long long> c(K);
    std::vector<long long> v(K);
    for(int i = 0 ; i < K ; i++){
        scanf("%lld",&r[i]);
        scanf("%lld",&c[i]);
        scanf("%lld",&v[i]);
    }
    solve(R, C, K, std::move(r), std::move(c), std::move(v));
    return 0;
}


Measured memory_bytes: 359436