program main
    use,intrinsic :: iso_fortran_env
    implicit none
    integer(int64):: r,c,k,i,x,y,in,v1,v2
    integer(int64), allocatable:: mass(:,:)
    integer(int64), allocatable:: dp(:,:,:)

    read*, r,c,k
    allocate(mass(r,c), source=0_8)
    allocate(dp(0:3,0:r,0:c),source=0_8)

    do i=1,k
        block; integer(int64):: x,y,v
            read*, y,x,v
            mass(y,x) = v
        end block
    end do

    do y=1,r
        do x=1,c
            dp(0,y,x) = maxval(dp(:,y-1,x))
            if (mass(y,x)>0) dp(1,y,x) = maxval(dp(:,y-1,x)) + mass(y,x)
            do in=1,3
                v1 = dp(in,y,x-1)
                v2 = 0
                if (mass(y,x) > 0)v2 = dp(in-1,y,x-1)+mass(y,x)
                dp(in,y,x) = max(dp(in,y,x),v1,v2)
            end do
        end do
    end do
    print'(i0)', maxval(dp(:,r,c))

end program main