import sys
input = sys.stdin.buffer.readline

#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return input().rstrip().decode()
def II(): return int(input())
def FI(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode()


def main():
	r,c,k=MI()
	G=[[0]*(c+1) for _ in range(r+1)]
	dp=[[0]*(c+1) for j in range(4)]
	for _ in range(k):
		rrr,ccc,v=MI()
		G[rrr][ccc]=v
	#print(G)

	#print(dp)

	for rr in range(1,r+1):
		for cc in range(1,c+1):
			if G[rr][cc]==0:
				for i in range(4):
					dp[i][cc]=max(dp[i][cc-1],dp[3][cc])
			else:
				dp[0][cc]=max(dp[3][cc],dp[0][cc-1])
				dp[1][cc]=max(dp[0][cc]+G[rr][cc],dp[1][cc-1])
				dp[2][cc]=max(dp[1][cc-1]+G[rr][cc],dp[2][cc-1],dp[1][cc])
				dp[3][cc]=max(dp[2][cc-1]+G[rr][cc],dp[3][cc-1],dp[2][cc])
	#print(dp)
	print(dp[-1][-1])















if __name__ == "__main__":
	main() import sys sys input = sys.stdin.buffer.readline input sys.stdin.buffer.readline sys.stdin.buffer sys.stdin sys stdin buffer readline def RD(): return input().rstrip().decode() RD def II(): return int(input()) II def FI(): return int(input()) FI def MI(): return map(int,input().split()) MI def MF(): return map(float,input().split()) MF def LI(): return list(map(int,input().split())) LI def LF(): return list(map(float,input().split())) LF def TI(): return tuple(map(int,input().split()))
# rstrip().decode() TI def main():
	r,c,k=MI()
	G=[[0]*(c+1) for _ in range(r+1)]
	dp=[[0]*(c+1) for j in range(4)]
	for _ in range(k):
		rrr,ccc,v=MI()
		G[rrr][ccc]=v
	#print(G)

	#print(dp)

	for rr in range(1,r+1):
		for cc in range(1,c+1):
			if G[rr][cc]==0:
				for i in range(4):
					dp[i][cc]=max(dp[i][cc-1],dp[3][cc])
			else:
				dp[0][cc]=max(dp[3][cc],dp[0][cc-1])
				dp[1][cc]=max(dp[0][cc]+G[rr][cc],dp[1][cc-1])
				dp[2][cc]=max(dp[1][cc-1]+G[rr][cc],dp[2][cc-1],dp[1][cc])
				dp[3][cc]=max(dp[2][cc-1]+G[rr][cc],dp[3][cc-1],dp[2][cc])
	#print(dp)
	print(dp[-1][-1]) main r,c,k=MI() r MI() MI c k [0]*(c+1) for _ in range(r+1) for _ in range(r+1) _ range(r+1) range r+1 r 1 for _ in range(r+1) [0]*(c+1) [0] 0 c+1 c 1 G=[[0]*(c+1) for _ in range(r+1)] G [[0]*(c+1) for _ in range(r+1)] [0]*(c+1) for j in range(4) for j in range(4) j range(4) range 4 for j in range(4) [0]*(c+1) [0] 0 c+1 c 1 dp=[[0]*(c+1) for j in range(4)] dp [[0]*(c+1) for j in range(4)] for _ in range(k):
		rrr,ccc,v=MI()
		G[rrr][ccc]=v
	#print(G)

	#print(dp)

	 _ range(k) range k rrr,ccc,v=MI() rrr MI() MI ccc v G[rrr][ccc]=v G[rrr][ccc] [rrr] G rrr ccc v for rr in range(1,r+1):
		for cc in range(1,c+1):
			if G[rr][cc]==0:
				for i in range(4):
					dp[i][cc]=max(dp[i][cc-1],dp[3][cc])
			else:
				dp[0][cc]=max(dp[3][cc],dp[0][cc-1])
				dp[1][cc]=max(dp[0][cc]+G[rr][cc],dp[1][cc-1])
				dp[2][cc]=max(dp[1][cc-1]+G[rr][cc],dp[2][cc-1],dp[1][cc])
				dp[3][cc]=max(dp[2][cc-1]+G[rr][cc],dp[3][cc-1],dp[2][cc])
	#print(dp)
	 rr range(1,r+1) range 1 r+1 r 1 for cc in range(1,c+1):
			if G[rr][cc]==0:
				for i in range(4):
					dp[i][cc]=max(dp[i][cc-1],dp[3][cc])
			else:
				dp[0][cc]=max(dp[3][cc],dp[0][cc-1])
				dp[1][cc]=max(dp[0][cc]+G[rr][cc],dp[1][cc-1])
				dp[2][cc]=max(dp[1][cc-1]+G[rr][cc],dp[2][cc-1],dp[1][cc])
				dp[3][cc]=max(dp[2][cc-1]+G[rr][cc],dp[3][cc-1],dp[2][cc])
	#print(dp)
	 cc range(1,c+1) range 1 c+1 c 1 if G[rr][cc]==0:
				for i in range(4):
					dp[i][cc]=max(dp[i][cc-1],dp[3][cc])
			else:
				dp[0][cc]=max(dp[3][cc],dp[0][cc-1])
				dp[1][cc]=max(dp[0][cc]+G[rr][cc],dp[1][cc-1])
				dp[2][cc]=max(dp[1][cc-1]+G[rr][cc],dp[2][cc-1],dp[1][cc])
				dp[3][cc]=max(dp[2][cc-1]+G[rr][cc],dp[3][cc-1],dp[2][cc])
	#print(dp)
	 G[rr][cc]==0 G[rr][cc] [rr] G rr cc 0 for i in range(4):
					dp[i][cc]=max(dp[i][cc-1],dp[3][cc])
			 i range(4) range 4 dp[i][cc]=max(dp[i][cc-1],dp[3][cc]) dp[i][cc] [i] dp i cc max(dp[i][cc-1],dp[3][cc]) max dp[i][cc-1] [i] dp i cc-1 cc 1 dp[3][cc] [3] dp 3 cc dp[0][cc]=max(dp[3][cc],dp[0][cc-1]) dp[0][cc] [0] dp 0 cc max(dp[3][cc],dp[0][cc-1]) max dp[3][cc] [3] dp 3 cc dp[0][cc-1] [0] dp 0 cc-1 cc 1 dp[1][cc]=max(dp[0][cc]+G[rr][cc],dp[1][cc-1]) dp[1][cc] [1] dp 1 cc max(dp[0][cc]+G[rr][cc],dp[1][cc-1]) max dp[0][cc]+G[rr][cc] dp[0][cc] [0] dp 0 cc G[rr][cc] [rr] G rr cc dp[1][cc-1] [1] dp 1 cc-1 cc 1 dp[2][cc]=max(dp[1][cc-1]+G[rr][cc],dp[2][cc-1],dp[1][cc]) dp[2][cc] [2] dp 2 cc max(dp[1][cc-1]+G[rr][cc],dp[2][cc-1],dp[1][cc]) max dp[1][cc-1]+G[rr][cc] dp[1][cc-1] [1] dp 1 cc-1 cc 1 G[rr][cc] [rr] G rr cc dp[2][cc-1] [2] dp 2 cc-1 cc 1 dp[1][cc] [1] dp 1 cc dp[3][cc]=max(dp[2][cc-1]+G[rr][cc],dp[3][cc-1],dp[2][cc]) dp[3][cc] [3] dp 3 cc max(dp[2][cc-1]+G[rr][cc],dp[3][cc-1],dp[2][cc]) max dp[2][cc-1]+G[rr][cc] dp[2][cc-1] [2] dp 2 cc-1 cc 1 G[rr][cc] [rr] G rr cc dp[3][cc-1] [3] dp 3 cc-1 cc 1 dp[2][cc] [2] dp 2 cc print(dp[-1][-1]) print dp[-1][-1] [-1] dp -1 -1 if __name__ == "__main__":
	main() __name__ == "__main__" __name__ "__main__" main() main def II(): return int(input()) def II(): return int(input()) II def MF(): return map(float,input().split()) def MF(): return map(float,input().split()) MF def RD(): return input().rstrip().decode() def RD(): return input().rstrip().decode() RD def TI(): return tuple(map(int,input().split()))
# rstrip().decode() def TI(): return tuple(map(int,input().split()))
# rstrip().decode() TI def main():
	r,c,k=MI()
	G=[[0]*(c+1) for _ in range(r+1)]
	dp=[[0]*(c+1) for j in range(4)]
	for _ in range(k):
		rrr,ccc,v=MI()
		G[rrr][ccc]=v
	#print(G)

	#print(dp)

	for rr in range(1,r+1):
		for cc in range(1,c+1):
			if G[rr][cc]==0:
				for i in range(4):
					dp[i][cc]=max(dp[i][cc-1],dp[3][cc])
			else:
				dp[0][cc]=max(dp[3][cc],dp[0][cc-1])
				dp[1][cc]=max(dp[0][cc]+G[rr][cc],dp[1][cc-1])
				dp[2][cc]=max(dp[1][cc-1]+G[rr][cc],dp[2][cc-1],dp[1][cc])
				dp[3][cc]=max(dp[2][cc-1]+G[rr][cc],dp[3][cc-1],dp[2][cc])
	#print(dp)
	print(dp[-1][-1]) def main():
	r,c,k=MI()
	G=[[0]*(c+1) for _ in range(r+1)]
	dp=[[0]*(c+1) for j in range(4)]
	for _ in range(k):
		rrr,ccc,v=MI()
		G[rrr][ccc]=v
	#print(G)

	#print(dp)

	for rr in range(1,r+1):
		for cc in range(1,c+1):
			if G[rr][cc]==0:
				for i in range(4):
					dp[i][cc]=max(dp[i][cc-1],dp[3][cc])
			else:
				dp[0][cc]=max(dp[3][cc],dp[0][cc-1])
				dp[1][cc]=max(dp[0][cc]+G[rr][cc],dp[1][cc-1])
				dp[2][cc]=max(dp[1][cc-1]+G[rr][cc],dp[2][cc-1],dp[1][cc])
				dp[3][cc]=max(dp[2][cc-1]+G[rr][cc],dp[3][cc-1],dp[2][cc])
	#print(dp)
	print(dp[-1][-1]) main input = sys.stdin.buffer.readline sys.stdin.buffer.readline input def LI(): return list(map(int,input().split())) def LI(): return list(map(int,input().split())) LI def MI(): return map(int,input().split()) def MI(): return map(int,input().split()) MI def FI(): return int(input()) def FI(): return int(input()) FI def LF(): return list(map(float,input().split())) def LF(): return list(map(float,input().split())) LF
import sys
input = sys.stdin.buffer.readline

#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return input().rstrip().decode()
def II(): return int(input())
def FI(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode()


def main():
	r,c,k=MI()
	G=[[0]*(c+1) for _ in range(r+1)]
	dp=[[0]*(c+1) for j in range(4)]
	for _ in range(k):
		rrr,ccc,v=MI()
		G[rrr][ccc]=v
	#print(G)

	#print(dp)

	for rr in range(1,r+1):
		for cc in range(1,c+1):
			if G[rr][cc]==0:
				for i in range(4):
					dp[i][cc]=max(dp[i][cc-1],dp[3][cc])
			else:
				dp[0][cc]=max(dp[3][cc],dp[0][cc-1])
				dp[1][cc]=max(dp[0][cc]+G[rr][cc],dp[1][cc-1])
				dp[2][cc]=max(dp[1][cc-1]+G[rr][cc],dp[2][cc-1],dp[1][cc])
				dp[3][cc]=max(dp[2][cc-1]+G[rr][cc],dp[3][cc-1],dp[2][cc])
	#print(dp)
	print(dp[-1][-1])















if __name__ == "__main__":
	main()
