// Original C++ solution (slower):
#include<cstdio>  

#include<cstring>  

#include<iostream>  

#include<algorithm>  

#define LL long long  

using namespace std;  

  

struct good  

{  

    int w,v;  

}g[110];  

  

bool cmp(good a,good b)  

{  

    return a.v > b.v;  

}  

good A[110],B[110],C[110],D[110];  

  

LL swa[110],swb[110],swc[110],swd[110];//重量的前缀和  

LL sva[110],svb[110],svc[110],svd[110];//价值的前缀和  

  

int main(void)  

{  

    int n,w,i,j,k,l;  

    int a,b,c,d;  

    while(scanf("%d%d",&n,&w)==2)  

    {  

        a = b = c = d = 0;  

        for(i=1;i<=n;i++)  

        {  

            scanf("%d%d",&g[i].w,&g[i].v);  

            if(g[i].w == g[1].w)  

                A[++a] = g[i];  

            if(g[i].w == g[1].w + 1)  

                B[++b] = g[i];  

            if(g[i].w == g[1].w + 2)  

                C[++c] = g[i];  

            if(g[i].w == g[1].w + 3)  

                D[++d] = g[i];  

        }  

        sort(A+1,A+a+1,cmp);  

        sort(B+1,B+b+1,cmp);  

        sort(C+1,C+c+1,cmp);  

        sort(D+1,D+d+1,cmp);  

        swa[0] = swb[0] = swc[0] = swd[0] = 0;  

        sva[0] = svb[0] = svc[0] = svd[0] = 0;  

        for(i=1;i<=a;i++)  

        {  

            swa[i] = swa[i-1] + A[i].w;  

            sva[i] = sva[i-1] + A[i].v;  

        }  

        for(i=1;i<=b;i++)  

        {  

            swb[i] = swb[i-1] + B[i].w;  

            svb[i] = svb[i-1] + B[i].v;  

        }  

        for(i=1;i<=c;i++)  

        {  

            swc[i] = swc[i-1] + C[i].w;  

            svc[i] = svc[i-1] + C[i].v;  

        }  

        for(i=1;i<=d;i++)  

        {  

            swd[i] = swd[i-1] + D[i].w;  

            svd[i] = svd[i-1] + D[i].v;  

        }  

        int sumv = 0;  

        int ans = 0;  

        for(i=0;i<=a;i++)  

        {  

            for(j=0;j<=b;j++)  

            {  

                for(k=0;k<=c;k++)  

                {  

                    for(l=0;l<=d;l++)  

                    {  

                        LL sum = swa[i] + swb[j] + swc[k] + swd[l];  

                        if(sum <= (LL)w)  

                        {  

                            ans = max((LL)ans,sva[i]+svb[j]+svc[k]+svd[l]);  

                        }  

                    }  

                }  

            }  

        }  

        cout << ans << endl;  

    }  

  

    return 0;  

}  

// Optimized solution to the same problem (faster):
#include<cstdio>

#include<cstring>

#include<algorithm>

const int MAXN=110;

long long w[5][MAXN],tot[5],base;



int main(){

	long long n,c;scanf("%lld%lld",&n,&c);

	for(int i=1;i<=n;i++){

		int x,v;scanf("%d%d",&x,&v);

		if(i==1)

			base=x;

		w[x-base][++tot[x-base]]=-v;

	}

	std::sort(w[0]+1,w[0]+tot[0]+1);

	std::sort(w[1]+1,w[1]+tot[1]+1);

	std::sort(w[2]+1,w[2]+tot[2]+1);

	std::sort(w[3]+1,w[3]+tot[3]+1);

	for(int i=0;i<4;i++)

		for(int j=1;j<=n;j++)

			w[i][j]+=w[i][j-1];

	long long ans=1;

	for(int i=0;i<=tot[0];i++)

		for(int j=0;j<=tot[1];j++)

			for(int k=0;k<=tot[2];k++)

				for(int l=0;l<=tot[3];l++){

					if(i*base+j*(base+1ll)+k*(base+2ll)+l*(base+3ll)>c)

						continue;

					ans=std::min(ans,(long long)w[0][i]+w[1][j]+w[2][k]+w[3][l]);

				}

	printf("%lld\n",-ans);

	return 0;

}

// Fastest known solution for this problem: