rows, cols, k = list(map(int, input().split()))

items = [[] for _ in range(rows+1)]

best = [0]*(cols+1)

for _ in range(k):

	r, c, v = list(map(int, input().split()))

	items[r].append([c, v])

for i in range(rows+1):

	items[i].sort()

ans = 0

for r in range(1, rows+1):

	dp = []

	best1, best2 = 0, 0

	Row = items[r]

	for c, v in Row:

		v1 = best[c] + v

		v2 = best1 + v

		v3 = best2 + v

		V = max(v1, v2, v3)

		dp.append(V)

		if v1 > best1:

			best1 = v1

		if v2 > best2:

			best2 = v2

		if ans < V:

			ans = V

	for j in range(len(dp)):

		if best[Row[j][0]] < dp[j]:

			best[Row[j][0]] = dp[j]

	for j in range(2, cols+1):

		if best[j] < best[j-1]:

			best[j] = best[j-1]

print(ans)

import sys



inp = [int(x) for x in sys.stdin.read().split()]; ii = 0



rows, cols, k = inp[ii:ii+3]; ii += 3

items = [[] for _ in range(rows+1)]

best = [0]*(cols+1)

for _ in range(k):

	r, c, v = inp[ii:ii+3]; ii += 3

	items[r].append([c, v])

for i in range(rows+1):

	items[i].sort()

ans = 0

for r in range(1, rows+1):

	dp = []

	best1, best2 = 0, 0

	Row = items[r]

	for c, v in Row:

		v1 = best[c] + v

		v2 = best1 + v

		v3 = best2 + v

		V = v1

		if V < v2:

			V = v2

		if V < v3:

			V = v3

		dp.append(V)

		if v1 > best1:

			best1 = v1

		if v2 > best2:

			best2 = v2

		if ans < V:

			ans = V

	for j in range(len(dp)):

		if best[Row[j][0]] < dp[j]:

			best[Row[j][0]] = dp[j]

	for j in range(2, cols+1):

		if best[j] < best[j-1]:

			best[j] = best[j-1]

print(ans)

rows, cols, k = list(map(int, input().split()))
items = [[] for _ in range(rows + 1)]
best = [0] * (cols + 1)
for _ in range(k):
    r, c, v = list(map(int, input().split()))
    items[r].append([c, v])
for i in range(rows + 1):
    items[i].sort()
ans = 0
for r in range(1, rows + 1):
    dp = []
    best1, best2 = 0, 0
    Row = items[r]
    for c, v in Row:
        v1 = best[c] + v
        v2 = best1 + v
        v3 = best2 + v
        V = max(v1, v2, v3)
        dp.append(V)
        if v1 > best1:
            best1 = v1
        if v2 > best2:
            best2 = v2
        if ans < V:
            ans = V
    for j in range(len(dp)):
        if best[Row[j][0]] < dp[j]:
            best[Row[j][0]] = dp[j]
    for j in range(2, cols + 1):
        if best[j] < best[j - 1]:
            best[j] = best[j - 1]
print(ans)

import sys

inp = [int(x) for x in sys.stdin.read().split()]
ii = 0
rows, cols, k = inp[ii : ii + 3]
ii += 3
items = [[] for _ in range(rows + 1)]
best = [0] * (cols + 1)
for _ in range(k):
    r, c, v = inp[ii : ii + 3]
    ii += 3
    items[r].append([c, v])
for i in range(rows + 1):
    items[i].sort()
ans = 0
for r in range(1, rows + 1):
    dp = []
    best1, best2 = 0, 0
    Row = items[r]
    for c, v in Row:
        v1 = best[c] + v
        v2 = best1 + v
        v3 = best2 + v
        V = v1
        if V < v2:
            V = v2
        if V < v3:
            V = v3
        dp.append(V)
        if v1 > best1:
            best1 = v1
        if v2 > best2:
            best2 = v2
        if ans < V:
            ans = V
    for j in range(len(dp)):
        if best[Row[j][0]] < dp[j]:
            best[Row[j][0]] = dp[j]
    for j in range(2, cols + 1):
        if best[j] < best[j - 1]:
            best[j] = best[j - 1]
print(ans)

-rows, cols, k = list(map(int, input().split())) +import sys + +inp = [int(x) for x in sys.stdin.read().split()] +ii = 0 +rows, cols, k = inp[ii : ii + 3] +ii += 3 -    r, c, v = list(map(int, input().split())) +    r, c, v = inp[ii : ii + 3] +    ii += 3 -        V = max(v1, v2, v3) +        V = v1 +        if V < v2: +            V = v2 +        if V < v3: +            V = v3