program abc145e
integer N,T,A(3000),B(3000)
integer,allocatable::DP(:,:)
integer ans
read*,N,T
allocate(dp(0:N,0:T))
do i=1,N
    read*,A(i),B(i)
end do
ans=0
do ii=1,N
    DP=0
    do i = 1,N
    	if(i==ii)then
        	dp(i+1,:)=dp(i,:)
            cycle
        endif
        do j = 0,T
            if (j >=A(i))then
                dp(i+1,j) = max(dp(i,J-A(i)) +B(i), dp(i,j))
            else
                dp(i+1,j) = dp(i,j)
            endif
        end do
    end do
    ans=max(ans,DP(N,T-1)+B(ii))
end do
print"(i0)",ans
end program