//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("avx2")
// 293206GT
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <unordered_set>
#include <stack>
#include <string>
#include<algorithm>
#include <random>
#include <bitset>
#include <chrono>

typedef long long ll;
#define int ll
using namespace std;
#define put(a) cout << (a) << '\n'
#define sqr(x) (x) * (x)
typedef pair<int, int> pii;
typedef long double ld;
typedef pair<ld, ld> pld;
typedef unsigned long long ull;

typedef vector<int> vi;
typedef vector<pii> vpii;
#define rep(x, y, a) for (int x = (y); x < (int)(a); ++x)
#define all(a) a.begin(), a.end()
#define chkmax(a, b) a = max(a, (b))
#define chkmin(a, b) a = min(a, (b))

namespace IO {

    template<class A, class B>
    ostream &operator<<(ostream &out, vector<pair<A, B>> a);

    template<class A>
    ostream &operator<<(ostream &out, vector<A> a);

    template<class A, class B>
    ostream &operator<<(ostream &out, pair<A, B> a) {
        out << a.first << " " << a.second;
        return out;
    }

    template<class A, class B>
    ostream &operator<<(ostream &out, vector<pair<A, B>> a) {
        for (pair<A, B> x: a)
            out << x.first << " " << x.second << '\n';
        return out;
    }

    template<class A>
    ostream &operator<<(ostream &out, vector<A> a) {
        for (A x: a) out << x << ' ';
        return out;
    }

    template<class A, class B>
    istream &operator>>(istream &in, pair<A, B> &a) {
        in >> a.first >> a.second;
        return in;
    }

    template<class A>
    istream &operator>>(istream &in, vector<A> &a) {
        for (A &x: a) in >> x;
        return in;
    }
}
using namespace IO;


mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

void solve() {
    int n,m, k1;
    cin >> n >> m >> k1;
    vector<vector<vi>> a(n, vector<vi>(m));
    rep(it, 0, k1) {
        int i, j, x;
        cin >> i >> j >> x;
        a[i - 1][j - 1].push_back(x);
    }
    vector<vector<vi>> dp(n, vector<vi>(m, vi(4)));
    dp[0][0][0] = 0;
    rep(i, 1, min(4ll, (int)a[0][0].size() + 1)) dp[0][0][i] = dp[0][0][i - 1] + a[0][0][i - 1];
    rep(i, 1, n) {
        rep(k, 0,4) {
            int cur = 0;

            rep(j, 0, a[i][0].size() + 1) {
                if (k < j) break;
                rep(l, 0, 4)
                chkmax(dp[i][0][k], dp[i - 1][0][l] + cur);
                if (j == a[i][0].size()) break;
                cur += a[i][0][j];
            }
        }
    }
    rep(i, 1, m) {
        rep(k, 0, 4) {

            int cur = 0;
            rep(j, 0, a[0][i].size() + 1) {
                if (k < j) break;
                chkmax(dp[0][i][k], dp[0][i - 1][k - j] + cur);
                if (j == a[0][i].size()) break;
                cur += a[0][i][j];
            }
        }
    }
    rep(i, 1, n) rep(j, 1, m) rep(k, 0, 4) {
        int cur = 0;
        rep(l, 0, a[i][j].size() + 1) {
            if (k - l < 0) break;
            rep(t, 0, 4)chkmax(dp[i][j][k], dp[i - 1][j][t] + cur);

            chkmax(dp[i][j][k], dp[i][j - 1][k - l] + cur);
            if (l != a[i][j].size())
            cur += a[i][j][l];
        }
    }
    put(*max_element(all(dp[n - 1][m - 1])));
}


signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout.precision(30);
//    freopen("input.txt", "r", stdin);
    int q = 1;
//    cin >> q;

    while (q--) solve();
}


Measured memory_bytes: 853248