program abc145e
type data
  integer::A,B
end type
integer N,T
type(data),allocatable::menu(:)
integer,allocatable::DP1(:,:),DP2(:,:)
integer ans
read*,N,T
allocate(DP1(0:N+1,0:T),DP2(0:N+1,0:T))
allocate(menu(N))
do i=1,N
    read*,menu(i)%A,menu(i)%B
end do

DP1=0;DP2=0
do i = 1,N
	do j = 0,T
    	if (j >= menu(i)%A)then
        	dp1(i+1,j) = max(dp1(i,J-menu(i)%A) +menu(i)%B, dp1(i,j))
        else
            dp1(i+1,j) = dp1(i,j)
        endif
    end do
end do
do i = N,1,-1
	do j = 0,T
    	if (j >= menu(i)%A)then
        	dp2(i-1,j) = max(dp2(i,J-menu(i)%A) +menu(i)%B, dp2(i,j))
        else
            dp2(i-1,j) = dp2(i,j)
        endif
    end do
end do
ans=0
do j=1,N
  do i=0,T-1
    ans=max(ans,DP1(j,i)+DP2(j,T-1-i)+menu(j)%B)
  end do
end do
print"(i0)",ans
end program
