// clang-format off
	#include <bits/stdc++.h>
	using namespace std; using ll = long long; using uint = unsigned int; using ull = unsigned long long;
	#define SFINAE(x, ...)	template <class, class = void> struct x : false_type {}; template <class T> struct x<T, void_t<__VA_ARGS__>> : true_type {};
	SFINAE(DefaultIO, decltype(cout << declval<T &>()))
	SFINAE(IsTuple, typename tuple_size<T>::type)
	SFINAE(Iterable, decltype(begin(declval<T>())))
	template <class T> constexpr char Space(const T &) { return (Iterable<T>::value or IsTuple<T>::value) ? '\n' : ' '; }
	template <auto &os> struct Writer {
		template <class T> void Impl(T const &t) const {
			if constexpr (DefaultIO<T>::value) os << t;
			else if constexpr (Iterable<T>::value) { int i = 0; for (auto &&x : t) ((i++) ? (os << Space(x), Impl(x)) : Impl(x)); }
			else if constexpr (IsTuple<T>::value) apply([this](auto const &... args) { int i = 0; (((i++) ? (os << ' ', Impl(args)) : Impl(args)), ...);}, t);
			else static_assert(IsTuple<T>::value, "No matching type for print");
		}
		template <class F, class... Ts> auto &operator()(F const &f, Ts const &... ts) const { return Impl(f), ((os << ' ', Impl(ts)), ...), os << '\n', *this; }
	};
	template <auto &is> struct Reader {
		template <class T> auto& Rd(T &t) const {
			if constexpr (DefaultIO<T>::value) is >> t;
			else if constexpr (Iterable<T>::value) for (auto &x : t) Rd(x);
			else if constexpr (IsTuple<T>::value) apply([this](auto &... args) { (Rd(args), ...); }, t);
			else static_assert(IsTuple<T>::value, "No matching type for read");
			return *this;
		}
		template <class T> auto operator[](T t) const { Rd(t); return t; }
		template <class... Ts> auto operator()(Ts... ts) const { (Rd(ts), ...); return tuple{move(ts)...}; }
	};
	#ifdef NARUT_LOCAL
	#define Debug(...) cerr << "\033[0;31m", Writer<cerr>{}(__VA_ARGS__), cerr << "\033[0m\n"
	#define ASSERT(...) if(not(__VA_ARGS__)) throw runtime_error("local assertion failed")
	#else
	#define Debug(...) 0
	#define ASSERT(...) 0
	#endif
	[[maybe_unused]] constexpr Reader<cin> Cin; [[maybe_unused]] constexpr Writer<cout> Cout;
	#define FOR(i, j, n) for (int i = int(j); i < int(n); ++i)
	#define ROF(i, j, n) for (int i = int(n) - 1; i >= int(j); --i)
	#define let auto const

// clang-format on

namespace narut {
	template <class T, size_t...> struct arr;
	template <class T, size_t N, size_t... Ns> struct arr<T, N, Ns...> {
		using type = array<typename arr<T, Ns...>::type, N>;
	};
	template <class T> struct arr<T> { using type = T; };
	template <class E, class C, class F> auto Each(C &c, F &&f) -> enable_if_t<is_same<decay_t<E>, decay_t<C>>::value> {
		f(c);
	}
	template <class E, class C, class F>
	auto Each(C &c, F &&f) -> enable_if_t<!is_same<decay_t<E>, decay_t<C>>::value> {
		for_each(begin(c), end(c), [&f](auto &&x) { Each<E>(x, f); });
	}
} // namespace narut
template <class T, size_t... Ns> using Arr = typename narut::arr<T, Ns...>::type;
using narut::Each;

Arr<array<int, 3>, 3001, 3001> A;
Arr<ll, 3001, 3001, 4> dp;

auto Main() {
	let[r, c, k] = Cin(0, 0, 0);
	map<pair<int, int>, vector<int>> items;
	FOR(ki, 0, k) {
		let[i, j, v] = Cin(0, 0, 0);
		items[{i, j}].push_back(v);
	}
	for (auto &[k, v] : items) {
		sort(begin(v), end(v));
		for (int i = 0; i < min(3, (int)v.size()); ++i) {
			A[k.first][k.second][i] = v[i];
		}
	}

	FOR(i, 1, r+1) {
		FOR(j, 1, c+1) {
			auto max_top = *max_element(dp[i - 1][j].begin(), dp[i - 1][j].end());
			// dp[i][j][0] = max(max_top, dp[i][j - 1][0]);
			array<ll, 4> ps{};
			partial_sum(A[i][j].begin(), A[i][j].end(), ps.begin() + 1);
			FOR(k, 0, 4) {
				dp[i][j][k] = max_top + ps[k];
				FOR(l, 0, k+1) { dp[i][j][k] = max(dp[i][j][k], dp[i][j - 1][l] + ps[k - l]); }
			}
		}
	}
	cout << *max_element(dp[r][c].begin(), dp[r][c].end());
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout << fixed << setprecision(10);
#ifdef NARUT_LOCAL
	assert(freopen("io/test.in", "r", stdin));
	cin.exceptions(cin.badbit | cin.failbit);
	cerr << fixed << setprecision(10);
#endif

	Main();
}


Measured memory_bytes: 412216