program all_you_can_eat
  implicit none
  integer :: n, t, a, b, dp(0:6000) = 0, i, j
  read(*,*) n, t
  do i = 1, n
    read(*,*) a, b
    do j = 6000, a, -1
      if (j-a < t) dp(j) = max(dp(j),dp(j-a)+b)
    end do
  end do
  write(*,'(i0)') maxval(dp)
end program all_you_can_eat