import sys
sys.setrecursionlimit(10**7)

readline = sys.stdin.buffer.readline
def readstr():return readline().rstrip().decode()
def readstrs():return list(readline().decode().split())
def readint():return int(readline())
def readints():return list(map(int,readline().split()))
def printrows(x):print('\n'.join(map(str,x)))
def printline(x):print(' '.join(map(str,x)))


r,c,k = readints()
a = [[0]*(c+1) for i in range(r+1)]

for i in range(k):
    R,C,V = readints()
    a[R][C] = V

dp = [0]*(r+1)*(c+1)*4

for x in range((r+1)*(c+1)*4):
    i = x//((c+1)*4)
    l = x%((c+1)*4)
    j = l//4
    l %= 4
    if i==0 or j==0:
        continue
    if l==0:
        dp[x] = max(dp[i*(c+1)*4 + (j-1)*4], dp[(i-1)*(c+1)*4 + j*4 + 3])
    else:
        dp[x] = max(dp[i*(c+1)*4 + (j-1)*4 + l], dp[(i-1)*(c+1)*4 + j*4 + 3]+a[i][j], dp[i*(c+1)*4 + (j-1)*4 + l-1]+a[i][j])

print(dp[-1]) import sys sys sys.setrecursionlimit(10**7) sys.setrecursionlimit sys setrecursionlimit 10**7 10 7 readline = sys.stdin.buffer.readline readline sys.stdin.buffer.readline sys.stdin.buffer sys.stdin sys stdin buffer readline def readstr():return readline().rstrip().decode() readstr def readstrs():return list(readline().decode().split()) readstrs def readint():return int(readline()) readint def readints():return list(map(int,readline().split())) readints def printrows(x):print('\n'.join(map(str,x))) printrows x x def printline(x):print(' '.join(map(str,x))) printline x x r,c,k = readints() r readints() readints c k [0]*(c+1) for i in range(r+1) for i in range(r+1) i range(r+1) range r+1 r 1 for i in range(r+1) [0]*(c+1) [0] 0 c+1 c 1 a = [[0]*(c+1) for i in range(r+1)] a [[0]*(c+1) for i in range(r+1)] for i in range(k):
    R,C,V = readints()
    a[R][C] = V i range(k) range k R,C,V = readints() R readints() readints C V a[R][C] = V a[R][C] [R] a R C V dp = [0]*(r+1)*(c+1)*4 dp [0]*(r+1)*(c+1)*4 [0]*(r+1)*(c+1) [0]*(r+1) [0] 0 r+1 r 1 c+1 c 1 4 for x in range((r+1)*(c+1)*4):
    i = x//((c+1)*4)
    l = x%((c+1)*4)
    j = l//4
    l %= 4
    if i==0 or j==0:
        continue
    if l==0:
        dp[x] = max(dp[i*(c+1)*4 + (j-1)*4], dp[(i-1)*(c+1)*4 + j*4 + 3])
    else:
        dp[x] = max(dp[i*(c+1)*4 + (j-1)*4 + l], dp[(i-1)*(c+1)*4 + j*4 + 3]+a[i][j], dp[i*(c+1)*4 + (j-1)*4 + l-1]+a[i][j]) x range((r+1)*(c+1)*4) range (r+1)*(c+1)*4 (r+1)*(c+1) r+1 r 1 c+1 c 1 4 i = x//((c+1)*4) i x//((c+1)*4) x (c+1)*4 c+1 c 1 4 l = x%((c+1)*4) l x%((c+1)*4) x (c+1)*4 c+1 c 1 4 j = l//4 j l//4 l 4 l %= 4 l 4 if i==0 or j==0:
        continue
     i==0 or j==0 i==0 i 0 j==0 j 0 continue if l==0:
        dp[x] = max(dp[i*(c+1)*4 + (j-1)*4], dp[(i-1)*(c+1)*4 + j*4 + 3])
    else:
        dp[x] = max(dp[i*(c+1)*4 + (j-1)*4 + l], dp[(i-1)*(c+1)*4 + j*4 + 3]+a[i][j], dp[i*(c+1)*4 + (j-1)*4 + l-1]+a[i][j]) l==0 l 0 dp[x] = max(dp[i*(c+1)*4 + (j-1)*4], dp[(i-1)*(c+1)*4 + j*4 + 3]) dp[x] dp x max(dp[i*(c+1)*4 + (j-1)*4], dp[(i-1)*(c+1)*4 + j*4 + 3]) max dp[i*(c+1)*4 + (j-1)*4] dp i*(c+1)*4 + (j-1)*4 i*(c+1)*4 i*(c+1) i c+1 c 1 4 (j-1)*4 j-1 j 1 4 dp[(i-1)*(c+1)*4 + j*4 + 3] dp (i-1)*(c+1)*4 + j*4 + 3 (i-1)*(c+1)*4 + j*4 (i-1)*(c+1)*4 (i-1)*(c+1) i-1 i 1 c+1 c 1 4 j*4 j 4 3 dp[x] = max(dp[i*(c+1)*4 + (j-1)*4 + l], dp[(i-1)*(c+1)*4 + j*4 + 3]+a[i][j], dp[i*(c+1)*4 + (j-1)*4 + l-1]+a[i][j]) dp[x] dp x max(dp[i*(c+1)*4 + (j-1)*4 + l], dp[(i-1)*(c+1)*4 + j*4 + 3]+a[i][j], dp[i*(c+1)*4 + (j-1)*4 + l-1]+a[i][j]) max dp[i*(c+1)*4 + (j-1)*4 + l] dp i*(c+1)*4 + (j-1)*4 + l i*(c+1)*4 + (j-1)*4 i*(c+1)*4 i*(c+1) i c+1 c 1 4 (j-1)*4 j-1 j 1 4 l dp[(i-1)*(c+1)*4 + j*4 + 3]+a[i][j] dp[(i-1)*(c+1)*4 + j*4 + 3] dp (i-1)*(c+1)*4 + j*4 + 3 (i-1)*(c+1)*4 + j*4 (i-1)*(c+1)*4 (i-1)*(c+1) i-1 i 1 c+1 c 1 4 j*4 j 4 3 a[i][j] [i] a i j dp[i*(c+1)*4 + (j-1)*4 + l-1]+a[i][j] dp[i*(c+1)*4 + (j-1)*4 + l-1] dp i*(c+1)*4 + (j-1)*4 + l-1 i*(c+1)*4 + (j-1)*4 + l i*(c+1)*4 + (j-1)*4 i*(c+1)*4 i*(c+1) i c+1 c 1 4 (j-1)*4 j-1 j 1 4 l 1 a[i][j] [i] a i j print(dp[-1]) print dp[-1] dp -1 r,c,k = readints() readints() r def readint():return int(readline()) def readint():return int(readline()) readint C,V = readints() readints() C def printrows(x):print('\n'.join(map(str,x))) def printrows(x):print('\n'.join(map(str,x))) printrows j = l//4 l//4 j c,k = readints() readints() c readline = sys.stdin.buffer.readline sys.stdin.buffer.readline readline def readints():return list(map(int,readline().split())) def readints():return list(map(int,readline().split())) readints k = readints() readints() k a = [[0]*(c+1) for i in range(r+1)] [[0]*(c+1) for i in range(r+1)] a dp = [0]*(r+1)*(c+1)*4 [0]*(r+1)*(c+1)*4 dp l %= 4 4 l def readstrs():return list(readline().decode().split()) def readstrs():return list(readline().decode().split()) readstrs def printline(x):print(' '.join(map(str,x))) def printline(x):print(' '.join(map(str,x))) printline V = readints() readints() V i = x//((c+1)*4) x//((c+1)*4) i R,C,V = readints() readints() R def readstr():return readline().rstrip().decode() def readstr():return readline().rstrip().decode() readstr l = x%((c+1)*4) x%((c+1)*4) l
import sys
sys.setrecursionlimit(10**7)

readline = sys.stdin.buffer.readline
def readstr():return readline().rstrip().decode()
def readstrs():return list(readline().decode().split())
def readint():return int(readline())
def readints():return list(map(int,readline().split()))
def printrows(x):print('\n'.join(map(str,x)))
def printline(x):print(' '.join(map(str,x)))


r,c,k = readints()
a = [[0]*(c+1) for i in range(r+1)]

for i in range(k):
    R,C,V = readints()
    a[R][C] = V

dp = [0]*(r+1)*(c+1)*4

for x in range((r+1)*(c+1)*4):
    i = x//((c+1)*4)
    l = x%((c+1)*4)
    j = l//4
    l %= 4
    if i==0 or j==0:
        continue
    if l==0:
        dp[x] = max(dp[i*(c+1)*4 + (j-1)*4], dp[(i-1)*(c+1)*4 + j*4 + 3])
    else:
        dp[x] = max(dp[i*(c+1)*4 + (j-1)*4 + l], dp[(i-1)*(c+1)*4 + j*4 + 3]+a[i][j], dp[i*(c+1)*4 + (j-1)*4 + l-1]+a[i][j])

print(dp[-1])