program picking_goods
  implicit none
  integer :: n, m, k, i, j, l
  integer(8) :: v
  integer(8), allocatable :: g(:, :), dp(:, :, :)
  read(*,*) n, m, k
  allocate(g(n, m), dp(0:n, 0:m, 3))
  g = 0
  do l = 1, k
    read(*,*) i, j, v
    g(i, j) = v
  end do
  dp = 0
  do i = 1, n
    do j = 1, m
      dp(i, j, 1) = max(maxval(dp(i - 1, j, :)) + g(i, j), dp(i, j - 1, 1))
      dp(i, j, 2) = max(dp(i, j - 1, 1) + g(i, j), dp(i, j - 1, 2))
      dp(i, j, 3) = max(dp(i, j - 1, 2) + g(i, j), dp(i, j - 1, 3))
    end do
  end do
  write(*,'(i0)') maxval(dp(n, m, :))
end program picking_goods