H, W, k = map(int, input().split())
"""
dp[k][i][j]
i行目、j番目まで来た時に、k個アイテムをとったときの価値の最大値
"""
fs = [[0]*(W+1) for i in range(H+1)]
dp = [[[-1]*(W+1) for i in range(H+1)] for j in range(4)]

# 価値を受け取る
for i in range(k):
    h, w, v = map(int, input().split())
    fs[h-1][w-1] += v

# initialize
dp[0][0][0] = 0
dp[1][0][0] = fs[0][0]

for h in range(H):
    for w in range(W):
        for i in range(4):
            if i == 0:
                dp[i][h][w+1] = max(dp[0][h][w], dp[0][h][w+1])
            else:
                dp[i][h][w+1] = max(dp[i][h][w], dp[i][h][w+1], dp[i-1][h][w]+fs[h][w+1])
    for w in range(W):
        dp[0][h+1][w] = max(dp[0][h][w],dp[1][h][w],dp[2][h][w],dp[3][h][w],0)
        dp[1][h+1][w] = dp[0][h+1][w] + fs[h+1][w]

mx = 0
for i in range(4):
    mx = max(dp[i][H-1][W-1],mx)
print(mx) H, W, k = map(int, input().split()) H map(int, input().split()) map int input().split() ().split () input split W k """
dp[k][i][j]
i行目、j番目まで来た時に、k個アイテムをとったときの価値の最大値
""" [0]*(W+1) for i in range(H+1) for i in range(H+1) i range(H+1) range H+1 H 1 for i in range(H+1) [0]*(W+1) [0] 0 W+1 W 1 fs = [[0]*(W+1) for i in range(H+1)] fs [[0]*(W+1) for i in range(H+1)] [[-1]*(W+1) for i in range(H+1)] for j in range(4) for j in range(4) j range(4) range 4 for j in range(4) [[-1]*(W+1) for i in range(H+1)] dp = [[[-1]*(W+1) for i in range(H+1)] for j in range(4)] dp [[[-1]*(W+1) for i in range(H+1)] for j in range(4)] for i in range(k):
    h, w, v = map(int, input().split())
    fs[h-1][w-1] += v

# initialize i range(k) range k h, w, v = map(int, input().split()) h map(int, input().split()) map int input().split() ().split () input split w v fs[h-1][w-1] += v fs[h-1][w-1] [h-1] fs h-1 h 1 w-1 w 1 v dp[0][0][0] = 0 dp[0][0][0] [0] [0] dp 0 0 0 0 dp[1][0][0] = fs[0][0] dp[1][0][0] [0] [1] dp 1 0 0 fs[0][0] [0] fs 0 0 for h in range(H):
    for w in range(W):
        for i in range(4):
            if i == 0:
                dp[i][h][w+1] = max(dp[0][h][w], dp[0][h][w+1])
            else:
                dp[i][h][w+1] = max(dp[i][h][w], dp[i][h][w+1], dp[i-1][h][w]+fs[h][w+1])
    for w in range(W):
        dp[0][h+1][w] = max(dp[0][h][w],dp[1][h][w],dp[2][h][w],dp[3][h][w],0)
        dp[1][h+1][w] = dp[0][h+1][w] + fs[h+1][w] h range(H) range H for w in range(W):
        for i in range(4):
            if i == 0:
                dp[i][h][w+1] = max(dp[0][h][w], dp[0][h][w+1])
            else:
                dp[i][h][w+1] = max(dp[i][h][w], dp[i][h][w+1], dp[i-1][h][w]+fs[h][w+1])
     w range(W) range W for i in range(4):
            if i == 0:
                dp[i][h][w+1] = max(dp[0][h][w], dp[0][h][w+1])
            else:
                dp[i][h][w+1] = max(dp[i][h][w], dp[i][h][w+1], dp[i-1][h][w]+fs[h][w+1])
     i range(4) range 4 if i == 0:
                dp[i][h][w+1] = max(dp[0][h][w], dp[0][h][w+1])
            else:
                dp[i][h][w+1] = max(dp[i][h][w], dp[i][h][w+1], dp[i-1][h][w]+fs[h][w+1])
     i == 0 i 0 dp[i][h][w+1] = max(dp[0][h][w], dp[0][h][w+1]) dp[i][h][w+1] [h] [i] dp i h w+1 w 1 max(dp[0][h][w], dp[0][h][w+1]) max dp[0][h][w] [h] [0] dp 0 h w dp[0][h][w+1] [h] [0] dp 0 h w+1 w 1 dp[i][h][w+1] = max(dp[i][h][w], dp[i][h][w+1], dp[i-1][h][w]+fs[h][w+1]) dp[i][h][w+1] [h] [i] dp i h w+1 w 1 max(dp[i][h][w], dp[i][h][w+1], dp[i-1][h][w]+fs[h][w+1]) max dp[i][h][w] [h] [i] dp i h w dp[i][h][w+1] [h] [i] dp i h w+1 w 1 dp[i-1][h][w]+fs[h][w+1] dp[i-1][h][w] [h] [i-1] dp i-1 i 1 h w fs[h][w+1] [h] fs h w+1 w 1 for w in range(W):
        dp[0][h+1][w] = max(dp[0][h][w],dp[1][h][w],dp[2][h][w],dp[3][h][w],0)
        dp[1][h+1][w] = dp[0][h+1][w] + fs[h+1][w] w range(W) range W dp[0][h+1][w] = max(dp[0][h][w],dp[1][h][w],dp[2][h][w],dp[3][h][w],0) dp[0][h+1][w] [h+1] [0] dp 0 h+1 h 1 w max(dp[0][h][w],dp[1][h][w],dp[2][h][w],dp[3][h][w],0) max dp[0][h][w] [h] [0] dp 0 h w dp[1][h][w] [h] [1] dp 1 h w dp[2][h][w] [h] [2] dp 2 h w dp[3][h][w] [h] [3] dp 3 h w 0 dp[1][h+1][w] = dp[0][h+1][w] + fs[h+1][w] dp[1][h+1][w] [h+1] [1] dp 1 h+1 h 1 w dp[0][h+1][w] + fs[h+1][w] dp[0][h+1][w] [h+1] [0] dp 0 h+1 h 1 w fs[h+1][w] [h+1] fs h+1 h 1 w mx = 0 mx 0 for i in range(4):
    mx = max(dp[i][H-1][W-1],mx) i range(4) range 4 mx = max(dp[i][H-1][W-1],mx) mx max(dp[i][H-1][W-1],mx) max dp[i][H-1][W-1] [H-1] [i] dp i H-1 H 1 W-1 W 1 mx print(mx) print mx k = map(int, input().split()) map(int, input().split()) k w, v = map(int, input().split()) map(int, input().split()) w H, W, k = map(int, input().split()) map(int, input().split()) H W, k = map(int, input().split()) map(int, input().split()) W dp = [[[-1]*(W+1) for i in range(H+1)] for j in range(4)] [[[-1]*(W+1) for i in range(H+1)] for j in range(4)] dp fs = [[0]*(W+1) for i in range(H+1)] [[0]*(W+1) for i in range(H+1)] fs h, w, v = map(int, input().split()) map(int, input().split()) h mx = max(dp[i][H-1][W-1],mx) max(dp[i][H-1][W-1],mx) mx v = map(int, input().split()) map(int, input().split()) v mx = 0 0 mx
H, W, k = map(int, input().split())
"""
dp[k][i][j]
i行目、j番目まで来た時に、k個アイテムをとったときの価値の最大値
"""
fs = [[0]*(W+1) for i in range(H+1)]
dp = [[[-1]*(W+1) for i in range(H+1)] for j in range(4)]

# 価値を受け取る
for i in range(k):
    h, w, v = map(int, input().split())
    fs[h-1][w-1] += v

# initialize
dp[0][0][0] = 0
dp[1][0][0] = fs[0][0]

for h in range(H):
    for w in range(W):
        for i in range(4):
            if i == 0:
                dp[i][h][w+1] = max(dp[0][h][w], dp[0][h][w+1])
            else:
                dp[i][h][w+1] = max(dp[i][h][w], dp[i][h][w+1], dp[i-1][h][w]+fs[h][w+1])
    for w in range(W):
        dp[0][h+1][w] = max(dp[0][h][w],dp[1][h][w],dp[2][h][w],dp[3][h][w],0)
        dp[1][h+1][w] = dp[0][h+1][w] + fs[h+1][w]

mx = 0
for i in range(4):
    mx = max(dp[i][H-1][W-1],mx)
print(mx)