      PROGRAM allYouCanEat
      implicit none
      integer :: n,t,ans
      integer,allocatable :: A(:),B(:)
      integer :: i,maxB, maxIndex,time,temp
      integer,allocatable :: dp(:,:), memo(:,:)
      
      read*,n,t
      allocate( A(1:n),B(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
      temp = 1
      do i = 1,n
        if( B(i)>maxB )THEN
          maxB     = B(i)
          temp     = A(i)
          maxIndex = i
        else if( B(i)==maxB )THEN
          if( A(i)>=temp )THEN
            maxB = B(i)
            temp = A(i)
            maxIndex = i
          end if
        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
      
      
      ans = dp(t-1,n) + maxB
      
      print*,ans
      
      END PROGRAM