program picking_goods
  implicit none
  integer :: n, m, k, r, c, i
  integer(8) :: v
  integer(8), allocatable :: g(:, :), h(:, :, :)
  read(*,*) n, m, k
  allocate(g(n, m), h(n, m, 0:3))
  g = 0
  h = -1
  do i = 1, k
    read(*,*) r, c, v
    g(r, c) = v
  end do
  h(1, 1, 0) = 0
  call dfs(1, 1, 0)
  write(*,'(i0)') max(h(n, m, 3), maxval(h(n, m, 0:2)) + g(n, m))
contains
  recursive subroutine dfs(r, c, k)
    integer, intent(in) :: r, c, k
    integer(8) :: v
    if (k == 3) then
      if (r < n) then
        if (h(r + 1, c, k) < h(r, c, k)) then
          h(r + 1, c, k) = h(r, c, k)
          call dfs(r + 1, c, k)
        end if
      end if
      if (c < m) then
        if (h(r, c + 1, 0) < h(r, c, k)) then
          h(r, c + 1, 0) = h(r, c, k)
          call dfs(r, c + 1, 0)
        end if
      end if
      return
    end if
    v = h(r, c, k) + g(r, c)
    if (r < n) then
      if (h(r + 1, c, k) < v) then
        h(r + 1, c, k + 1) = v
        call dfs(r + 1, c, k + 1)
      end if
    end if
    if (c < m) then
      if (h(r, c + 1, 0) < v) then
        h(r, c + 1, 0) = v
        call dfs(r, c + 1, 0)
      end if
    end if
  end
end program picking_goods