#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ for(auto it : P) { s << "<" << it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ for(auto it : P) { s << "<" << it.first << "->" << it.second << "> "; } return s << endl; }

int R, C, K;
vector<vector<long long>> v;

long long dp[3100][3100][5];

int main() {
    while (cin >> R >> C >> K) {
        v.assign(R+1, vector<long long>(C+1, -1));
        for (int i = 0; i < K; ++i) {
            long long r, c, t;
            cin >> r >> c >> t;
            v[r][c] = t;
        }
        memset(dp, 0, sizeof(dp));
        for (int i = 0; i <= R; ++i) {
            for (int j = 0; j <= C; ++j) {
                for (int k = 0; k <= 3; ++k) {
                    // ue
                    if (i < R) {
                        chmax(dp[i+1][j][0], dp[i][j][k]);
                        if (v[i+1][j] != -1) {
                            chmax(dp[i+1][j][1], dp[i][j][k] + v[i+1][j]);
                        }
                    }
                    // migi
                    if (j < C) {
                        chmax(dp[i][j+1][k], dp[i][j][k]);
                        if (v[i][j+1] != -1 && k+1 <= 3) {
                            chmax(dp[i][j+1][k+1], dp[i][j][k] + v[i][j+1]);
                        }
                    }
                }
            }
        }
        long long res = 0;
        for (int k = 0; k <= 3; ++k) chmax(res, dp[R][C][k]);
        cout << res << endl;
    }
}

/*
using Item = pair<int, long long>;
int R, C, K;
vector<vector<Item>> items;
vector<vector<int>> ys;

long long solve() {
    vector<vector<long long>> dp(R+1, vector<long long>(C+1, 0));
    for (int r = 1; r <= R; ++r) {
        for (int c = 0; c <= C; ++c) {
            if (dp[r][c] > 0) {
                cout << r << ", " << c << ": " << dp[r][c] << endl;
            }
            auto it = lower_bound(ys[r].begin(), 
            ys[r].end(), c) - ys[r].begin();

            chmax(dp[r][c], dp[r-1][c]);
            long long vadd = 0;
            for (int add = 0; add <= 2; ++add) {
                if (it + add < ys[r].size()) {
                    int it2 = it + add;
                    int c2 = ys[r][it2];
                    vadd += items[r][it2].second;
                    chmax(dp[r][c2], dp[r-1][c] + vadd);
                }
            }
        }
    }
    long long res = 0;
    for (int r = 0; r <= R; ++r) {
        for (int c = 0; c <= C; ++c) {
            chmax(res, dp[r][c]);
        }
    }
    return res;
}

int main() {
    while (cin >> R >> C >> K) {
        items.assign(R+1, vector<Item>());
        ys.assign(R+1, vector<int>());
        for (int i = 0; i < K; ++i) {
            int r, c;
            long long v;
            cin >> r >> c >> v;
            items[r].push_back(Item(c, v));
        }
        for (int r = 0; r <= R; ++r) {
            sort(items[r].begin(), items[r].end());
            for (int i = 0; i < items[r].size(); ++i) {
                ys[r].push_back(items[r][i].first);
            }
        }
        cout << solve() << endl;
    }
}




*/












Measured memory_bytes: 449032