let () = Scanf.scanf "%d %d %d\n" @@ fun r c k ->
  let vss = Array.make_matrix c r 0 in
  for i = 0 to k - 1 do
    Scanf.scanf "%d %d %d\n" @@ fun r c v ->
      vss.(c - 1).(r - 1) <- v
  done;
  let dp =
    Array.init c @@ fun _ ->
      Array.init r @@ fun _ ->
        Array.init 4 @@ fun _ -> min_int in
  dp.(0).(0).(0) <- 0;
  dp.(0).(0).(1) <- vss.(0).(0);
  for i = 1 to c - 1 do
    for k = 0 to 3 do
      dp.(i).(0).(k) <- max dp.(i).(0).(k) dp.(i - 1).(0).(k)
    done;
    for k = 3 downto 1 do
      dp.(i).(0).(k) <- max dp.(i).(0).(k) (dp.(i).(0).(k - 1) + vss.(i).(0))
    done
  done;
  for j = 1 to r - 1 do
    for k = 0 to 3 do
      dp.(0).(j).(0) <- max dp.(0).(j).(0) dp.(0).(j - 1).(k)
    done;
    dp.(0).(j).(1) <- max dp.(0).(j).(1) (dp.(0).(j).(0) + vss.(0).(j))
  done;
  for i = 1 to c - 1 do
    for j = 1 to r - 1 do
      for k = 0 to 3 do
        dp.(i).(j).(k) <- max dp.(i).(j).(k) dp.(i - 1).(j).(k)
      done;
      for k = 0 to 3 do
        dp.(i).(j).(0) <- max dp.(i).(j).(0) dp.(i).(j - 1).(k)
      done;
      for k = 3 downto 1 do
        dp.(i).(j).(k) <- max dp.(i).(j).(k) (dp.(i).(j).(k - 1) + vss.(i).(j))
      done
    done
  done;
  Printf.printf "%d\n" @@ Array.fold_left max min_int dp.(c - 1).(r - 1)
