program ARC073D
    implicit none
    integer(8)::N,W,i,j,k,l,a,b,c,d,Vall(100,4),wi,w1,vi,vcount(4),ans,wall,v
    read*,N,W
    vcount=0
    Vall=0
    ans=0
    do i=1,N
        read*,wi,vi
        if(i==1)w1=wi
        vcount(wi-w1+1)=vcount(wi-w1+1)+1
        Vall(vcount(wi-w1+1),wi-w1+1)=vi
    end do

    do i=1,4
        call heapsort(100,Vall(:,i))
    end do

    do i=0,vcount(1)
        do j=0,vcount(2)
            do k=0,vcount(3)
                do l=0,vcount(4)
                    wall=i*w1+j*(w1+1)+k*(w1+2)+l*(w1+3)
                    if(wall<=W)then
                        v=0
                        do a=0,i-1
                            v=v+Vall(100-a,1)
                        end do

                        do b=0,j-1
                            v=v+Vall(100-b,2)
                        end do

                        do c=0,k-1
                            v=v+Vall(100-c,3)
                        end do

                        do d=0,l-1
                            v=v+Vall(100-d,4)
                        end do
                        ans=max(ans,v)
                    end if
                end do
            end do
        end do
    end do

    print'(i0)',ans
end program ARC073D

subroutine heapsort(n,array)
    implicit none
    integer,intent(in) :: n
    integer(8),intent(inout) :: array(1:n)
   
    integer(8) ::i,k,j,l
    integer(8) :: t
   
    if(n.eq.1)return
  
    l=n/2+1
    k=n
    do while(k.ne.1)
       if(l.gt.1)then
          l=l-1
          t=array(L)
       else
          t=array(k)
          array(k)=array(1)
          k=k-1
          if(k.eq.1) then
             array(1)=t
             exit
          endif
       endif
       i=l
       j=l+l
       do while(j.le.k)
          if(j.lt.k)then
             if(array(j).lt.array(j+1))j=j+1
          endif
          if (t.lt.array(j))then
             array(i)=array(j)
             i=j
             j=j+j
          else
             j=k+1
          endif
       enddo
       array(i)=t
    enddo
  
    return
  end subroutine heapsort