#include <iostream>
#include <string>
#include <cmath>
using namespace std;

long long int Map[3000][3000] = {}, Score[3000][3000][4] = {};


int main(){
    
    long long int i, j, R, C, K, x, y, ans;
    cin >> R >> C >> K;
    
    for (i = 0; i < K; i++){
        cin >> x >> y;
        x -= 1;
        y -= 1;
        cin >> Map[x][y];
    }
    
    for (j = 0; j < C; j++){
        for (i = 0; i < R; i++){
            
            if ( Map[i][j] == 0){
                
                if (i == 0 && j == 0){
                    
                } else if (i == 0){
                    Score[i][j][0] = Score[i][j - 1][0];
                    Score[i][j][1] = Score[i][j - 1][1];
                    Score[i][j][2] = Score[i][j - 1][2];
                    Score[i][j][3] = Score[i][j - 1][3];
                    
                } else if (j == 0){
                    Score[i][j][0] = max( Score[i - 1][j][0],
                                         ( max( Score[i - 1][j][1],
                                               max( Score[i - 1][j][2], Score[i][j - 1][3] ))));

                } else {
                    Score[i][j][0] = max( Score[i][j - 1][0],
                                         max( Score[i - 1][j][0],
                                             max( Score[i - 1][j][1],
                                                 max( Score[i - 1][j][2], Score[i - 1][j][3] ))));
                    Score[i][j][1] = Score[i][j - 1][1];
                    Score[i][j][2] = Score[i][j - 1][2];
                    Score[i][j][3] = Score[i][j - 1][3];
                }
                
            } else {
                if (i == 0 && j == 0){
                    Score[i][j][1] = Map[i][j];
                    
                } else if (i == 0){
                    Score[i][j][0] = Score[i][j - 1][0];
                    Score[i][j][1] = max( (Map[i][j] + Score[i][j - 1][0]), (Score[i][j - 1][1]) );
                    Score[i][j][2] = max( (Map[i][j] + Score[i][j - 1][1]), (Score[i][j - 1][2]) );
                    Score[i][j][3] = max( (Map[i][j] + Score[i][j - 1][2]), (Score[i][j - 1][3]) );
                    
                } else if (j == 0){
                    Score[i][j][0] = max( Score[i - 1][j][0],
                                         ( max( Score[i - 1][j][1],
                                               max( Score[i - 1][j][2], Score[i - 1][j][3] ))));
                    Score[i][j][1] = max( Score[i - 1][j][0],
                                         ( max( Score[i - 1][j][1],
                                               max( Score[i - 1][j][2], Score[i - 1][j][3] )))) + Map[i][j];

                } else {
                    Score[i][j][0] = max( Score[i][j - 1][0],
                                         ( max( Score[i - 1][j][0],
                                               max( Score[i - 1][j][1],
                                                   max( Score[i - 1][j][2], Score[i - 1][j][3] )))));
                    Score[i][j][1] = max( (Map[i][j] + Score[i][j][0]), Score[i][j - 1][1] );
                    Score[i][j][2] = max( (Map[i][j] + Score[i][j - 1][1]), Score[i][j - 1][2] );
                    Score[i][j][3] = max( (Map[i][j] + Score[i][j - 1][2]), Score[i][j - 1][3] );
                }
            }
        }
    }
    
//    for (j = 0; j < C; j++){
//        for (i = 0; i < R; i++){
//
//        cout << Score[i][j][0] << ' ' << Score[i][j][1] << ' '
//            << Score[i][j][2] << ' ' << Score[i][j][3] << "\n";
//
//        }
//    }
    
    ans = max( Score[R - 1][C - 1][0],
                         max( Score[R - 1][C - 1][1],
                             max( Score[R - 1][C - 1][2], Score[R - 1][C - 1][3])));

    
    cout << ans << "\n";
    
    return 0;
}



Measured memory_bytes: 354532