      PROGRAM allYouCanEat
      implicit none
      integer :: n,t,ans
      integer,allocatable :: A(:),B(:),flag(:)
      integer :: i,maxB, maxIndex,time,temp
      integer,allocatable :: dp(:,:), memo(:,:)
      
      read*,n,t
      allocate( A(1:n),B(1:n),flag(1:n) )
      allocate( dp(1:t-1,0:n),memo(1:t-1,0:n) )
      do i = 1,n
        !A:timeCost B:value
        read*,A(i),B(i)
      end do
      
      !find maxB
      maxB = 1
      do i = 1,n
        if( B(i)>=maxB )THEN
          maxB     = B(i)
          maxIndex = i
        end if
      end do
      
      B(maxIndex) = -1
      
      
      dp(:,:)   = 0
      memo(:,:) = 0
      do i = 1,n
        do time = 1,t-1
          
          if( time-A(i)<=0 )THEN
            temp = -1
          else
            temp = dp(time-A(i),i-1) + B(i)
          end if
          
          if( temp>=dp(time,i-1) )THEN
            memo(time,i) = 1
            dp  (time,i) = temp
          else
            dp  (time,i) = dp(time,i-1)
          end if
          
        end do
      end do
      
      
      
    !  time = t-1
    !  flag(:) = 0
    !  !trace memo
    !  do i = n,1,-1
    !    if( memo(i,time)==1 )THEN
    !      time = time - A(i)
    !      flag(i) = 1
    !    end if
    !  end do
      
      
      ans = dp(t-1,n) + maxB
      
      print*,ans
      
      END PROGRAM