local mmi, mma = math.min, math.max
local r, c, k = io.read("*n", "*n", "*n")
local item_row = {}
for i = 1, r do
  item_row[i] = {}
end
for i = 1, k do
  local ra, ca, v = io.read("*n", "*n", "*n")
  table.insert(item_row[ra], {ca, v})
end
for i = 1, r do
  table.sort(item_row[i], function(a, b) return a[1] < b[1] end)
end

local v1, v2, v3 = 0, 0, 0
local function box_reset(val)
  v1, v2, v3 = val, 0, 0
end
local function box_update(val)
  if val <= v3 then return end
  v3 = val
  if val <= v2 then return end
  v2, v3 = val, v2
  if v1 < val then
    v1, v2 = val, v1
  end
end
local function getboxval()
  return v1 + v2 + v3
end

local dp1, dp2 = {}, {}
for i = 1, r do
  local tbl = dp1
  local tbl2 = dp2
  -- local tbl = i % 2 == 1 and dp1 or dp2
  -- local tbl2 = i % 2 == 1 and dp2 or dp1
  if i == 1 then
    for j = 1, c do
      tbl[j] = 0
    end
  else
    for j = 1, c do
      tbl[j] = tbl2[j]
    end
  end
  for j = 1, c - 1 do
    tbl[j + 1] = mma(tbl[j + 1], tbl[j])
  end
  for j = 1, c do
    tbl2[j] = 0
  end
  local item = item_row[i]
  for j = 1, #item do
    local col, val = item[j][1], item[j][2]
    box_reset(val)
    local baseval = tbl[col]
    tbl2[col] = mma(tbl2[col], baseval + getboxval())
    for k = j + 1, #item do
      local c2, v2 = item[k][1], item[k][2]
      box_update(v2)
      tbl2[c2] = mma(tbl2[c2], baseval + getboxval())
    end
  end
  tbl2[1] = mma(tbl2[1], tbl[1])
  for j = 2, c do
    tbl2[j] = mma(tbl2[j], tbl2[j - 1], tbl[j])
  end
end
-- print(dp1[1], dp1[2])
-- print(dp2[1], dp2[2])
print(dp2[c])
