"""
dp[i][j][k] => i行目、j列のマスまで見る。k個取る時の最高値。
"""
def main():
    import sys
    input = sys.stdin.readline
    R,C,K = map(int,input().split())
    items = [[0]*C for _ in range(R)]
    for _ in range(K):
        r,c,v = map(int,input().split())
        items[r-1][c-1] = v

    dp = [[0]*4 for _ in range(C)]

    for i in range(R):
        for j in range(C):
            v = items[i][j]
            if i == 0 and j == 0 and v != 0:
                dp[j][1] = v
                continue
            
            if i != 0:
                #上から降りてくる場合の価値を求める
                #i行目j列のアイテムを取らない場合
                dp[j][0] = max(dp[j])
                #i行目j列のアイテムを取る場合
                if v!=0:
                    dp[j][1] = dp[j][0] + v

            #左から入ってくる場合の価値を求める
            if j != 0:
                dp[j][0] = max(dp[j][0],dp[j-1][0])
                if v == 0:
                    for k in range(1,4):
                        dp[j][k] = max(dp[j][k],dp[j-1][k])
                else:
                    for k in range(1,4):
                        dp[j][k] = max(dp[j][k],dp[j-1][k],dp[j-1][k-1]+v)
    print(max(dp[-1]))
main() """
dp[i][j][k] => i行目、j列のマスまで見る。k個取る時の最高値。
""" def main():
    import sys
    input = sys.stdin.readline
    R,C,K = map(int,input().split())
    items = [[0]*C for _ in range(R)]
    for _ in range(K):
        r,c,v = map(int,input().split())
        items[r-1][c-1] = v

    dp = [[0]*4 for _ in range(C)]

    for i in range(R):
        for j in range(C):
            v = items[i][j]
            if i == 0 and j == 0 and v != 0:
                dp[j][1] = v
                continue
            
            if i != 0:
                #上から降りてくる場合の価値を求める
                #i行目j列のアイテムを取らない場合
                dp[j][0] = max(dp[j])
                #i行目j列のアイテムを取る場合
                if v!=0:
                    dp[j][1] = dp[j][0] + v

            #左から入ってくる場合の価値を求める
            if j != 0:
                dp[j][0] = max(dp[j][0],dp[j-1][0])
                if v == 0:
                    for k in range(1,4):
                        dp[j][k] = max(dp[j][k],dp[j-1][k])
                else:
                    for k in range(1,4):
                        dp[j][k] = max(dp[j][k],dp[j-1][k],dp[j-1][k-1]+v)
    print(max(dp[-1])) main import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline R,C,K = map(int,input().split()) R map(int,input().split()) map int input().split() ().split () input split C K [0]*C for _ in range(R) for _ in range(R) _ range(R) range R for _ in range(R) [0]*C [0] 0 C items = [[0]*C for _ in range(R)] items [[0]*C for _ in range(R)] for _ in range(K):
        r,c,v = map(int,input().split())
        items[r-1][c-1] = v

     _ range(K) range K r,c,v = map(int,input().split()) r map(int,input().split()) map int input().split() ().split () input split c v items[r-1][c-1] = v items[r-1][c-1] [r-1] items r-1 r 1 c-1 c 1 v [0]*4 for _ in range(C) for _ in range(C) _ range(C) range C for _ in range(C) [0]*4 [0] 0 4 dp = [[0]*4 for _ in range(C)] dp [[0]*4 for _ in range(C)] for i in range(R):
        for j in range(C):
            v = items[i][j]
            if i == 0 and j == 0 and v != 0:
                dp[j][1] = v
                continue
            
            if i != 0:
                #上から降りてくる場合の価値を求める
                #i行目j列のアイテムを取らない場合
                dp[j][0] = max(dp[j])
                #i行目j列のアイテムを取る場合
                if v!=0:
                    dp[j][1] = dp[j][0] + v

            #左から入ってくる場合の価値を求める
            if j != 0:
                dp[j][0] = max(dp[j][0],dp[j-1][0])
                if v == 0:
                    for k in range(1,4):
                        dp[j][k] = max(dp[j][k],dp[j-1][k])
                else:
                    for k in range(1,4):
                        dp[j][k] = max(dp[j][k],dp[j-1][k],dp[j-1][k-1]+v)
     i range(R) range R for j in range(C):
            v = items[i][j]
            if i == 0 and j == 0 and v != 0:
                dp[j][1] = v
                continue
            
            if i != 0:
                #上から降りてくる場合の価値を求める
                #i行目j列のアイテムを取らない場合
                dp[j][0] = max(dp[j])
                #i行目j列のアイテムを取る場合
                if v!=0:
                    dp[j][1] = dp[j][0] + v

            #左から入ってくる場合の価値を求める
            if j != 0:
                dp[j][0] = max(dp[j][0],dp[j-1][0])
                if v == 0:
                    for k in range(1,4):
                        dp[j][k] = max(dp[j][k],dp[j-1][k])
                else:
                    for k in range(1,4):
                        dp[j][k] = max(dp[j][k],dp[j-1][k],dp[j-1][k-1]+v)
     j range(C) range C v = items[i][j] v items[i][j] [i] items i j if i == 0 and j == 0 and v != 0:
                dp[j][1] = v
                continue
            
             i == 0 and j == 0 and v != 0 i == 0 and j == 0 i == 0 i 0 j == 0 j 0 v != 0 v 0 dp[j][1] = v dp[j][1] [j] dp j 1 v continue if i != 0:
                #上から降りてくる場合の価値を求める
                #i行目j列のアイテムを取らない場合
                dp[j][0] = max(dp[j])
                #i行目j列のアイテムを取る場合
                if v!=0:
                    dp[j][1] = dp[j][0] + v

            #左から入ってくる場合の価値を求める
             i != 0 i 0 dp[j][0] = max(dp[j]) dp[j][0] [j] dp j 0 max(dp[j]) max dp[j] dp j if v!=0:
                    dp[j][1] = dp[j][0] + v

            #左から入ってくる場合の価値を求める
             v!=0 v 0 dp[j][1] = dp[j][0] + v dp[j][1] [j] dp j 1 dp[j][0] + v dp[j][0] [j] dp j 0 v if j != 0:
                dp[j][0] = max(dp[j][0],dp[j-1][0])
                if v == 0:
                    for k in range(1,4):
                        dp[j][k] = max(dp[j][k],dp[j-1][k])
                else:
                    for k in range(1,4):
                        dp[j][k] = max(dp[j][k],dp[j-1][k],dp[j-1][k-1]+v)
     j != 0 j 0 dp[j][0] = max(dp[j][0],dp[j-1][0]) dp[j][0] [j] dp j 0 max(dp[j][0],dp[j-1][0]) max dp[j][0] [j] dp j 0 dp[j-1][0] [j-1] dp j-1 j 1 0 if v == 0:
                    for k in range(1,4):
                        dp[j][k] = max(dp[j][k],dp[j-1][k])
                else:
                    for k in range(1,4):
                        dp[j][k] = max(dp[j][k],dp[j-1][k],dp[j-1][k-1]+v)
     v == 0 v 0 for k in range(1,4):
                        dp[j][k] = max(dp[j][k],dp[j-1][k])
                 k range(1,4) range 1 4 dp[j][k] = max(dp[j][k],dp[j-1][k]) dp[j][k] [j] dp j k max(dp[j][k],dp[j-1][k]) max dp[j][k] [j] dp j k dp[j-1][k] [j-1] dp j-1 j 1 k for k in range(1,4):
                        dp[j][k] = max(dp[j][k],dp[j-1][k],dp[j-1][k-1]+v)
     k range(1,4) range 1 4 dp[j][k] = max(dp[j][k],dp[j-1][k],dp[j-1][k-1]+v) dp[j][k] [j] dp j k max(dp[j][k],dp[j-1][k],dp[j-1][k-1]+v) max dp[j][k] [j] dp j k dp[j-1][k] [j-1] dp j-1 j 1 k dp[j-1][k-1]+v dp[j-1][k-1] [j-1] dp j-1 j 1 k-1 k 1 v print(max(dp[-1])) print max(dp[-1]) max dp[-1] dp -1 main() main def main():
    import sys
    input = sys.stdin.readline
    R,C,K = map(int,input().split())
    items = [[0]*C for _ in range(R)]
    for _ in range(K):
        r,c,v = map(int,input().split())
        items[r-1][c-1] = v

    dp = [[0]*4 for _ in range(C)]

    for i in range(R):
        for j in range(C):
            v = items[i][j]
            if i == 0 and j == 0 and v != 0:
                dp[j][1] = v
                continue
            
            if i != 0:
                #上から降りてくる場合の価値を求める
                #i行目j列のアイテムを取らない場合
                dp[j][0] = max(dp[j])
                #i行目j列のアイテムを取る場合
                if v!=0:
                    dp[j][1] = dp[j][0] + v

            #左から入ってくる場合の価値を求める
            if j != 0:
                dp[j][0] = max(dp[j][0],dp[j-1][0])
                if v == 0:
                    for k in range(1,4):
                        dp[j][k] = max(dp[j][k],dp[j-1][k])
                else:
                    for k in range(1,4):
                        dp[j][k] = max(dp[j][k],dp[j-1][k],dp[j-1][k-1]+v)
    print(max(dp[-1])) def main():
    import sys
    input = sys.stdin.readline
    R,C,K = map(int,input().split())
    items = [[0]*C for _ in range(R)]
    for _ in range(K):
        r,c,v = map(int,input().split())
        items[r-1][c-1] = v

    dp = [[0]*4 for _ in range(C)]

    for i in range(R):
        for j in range(C):
            v = items[i][j]
            if i == 0 and j == 0 and v != 0:
                dp[j][1] = v
                continue
            
            if i != 0:
                #上から降りてくる場合の価値を求める
                #i行目j列のアイテムを取らない場合
                dp[j][0] = max(dp[j])
                #i行目j列のアイテムを取る場合
                if v!=0:
                    dp[j][1] = dp[j][0] + v

            #左から入ってくる場合の価値を求める
            if j != 0:
                dp[j][0] = max(dp[j][0],dp[j-1][0])
                if v == 0:
                    for k in range(1,4):
                        dp[j][k] = max(dp[j][k],dp[j-1][k])
                else:
                    for k in range(1,4):
                        dp[j][k] = max(dp[j][k],dp[j-1][k],dp[j-1][k-1]+v)
    print(max(dp[-1])) main
"""
dp[i][j][k] => i行目、j列のマスまで見る。k個取る時の最高値。
"""
def main():
    import sys
    input = sys.stdin.readline
    R,C,K = map(int,input().split())
    items = [[0]*C for _ in range(R)]
    for _ in range(K):
        r,c,v = map(int,input().split())
        items[r-1][c-1] = v

    dp = [[0]*4 for _ in range(C)]

    for i in range(R):
        for j in range(C):
            v = items[i][j]
            if i == 0 and j == 0 and v != 0:
                dp[j][1] = v
                continue
            
            if i != 0:
                #上から降りてくる場合の価値を求める
                #i行目j列のアイテムを取らない場合
                dp[j][0] = max(dp[j])
                #i行目j列のアイテムを取る場合
                if v!=0:
                    dp[j][1] = dp[j][0] + v

            #左から入ってくる場合の価値を求める
            if j != 0:
                dp[j][0] = max(dp[j][0],dp[j-1][0])
                if v == 0:
                    for k in range(1,4):
                        dp[j][k] = max(dp[j][k],dp[j-1][k])
                else:
                    for k in range(1,4):
                        dp[j][k] = max(dp[j][k],dp[j-1][k],dp[j-1][k-1]+v)
    print(max(dp[-1]))
main()