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