// Slower C++ solution:
#include <stdio.h>

#include <math.h>

#include <string.h>

#include <algorithm>

#include <iostream>

#include <string>

#include <time.h>

#include <queue>

#include <list>

#include <map>

#include <set>

#include <vector>

#include <stack>

#include <string.h>



#define sf scanf

#define pf printf

#define lf double

#define ll long long

#define p123 printf("123\n");

#define pn printf("\n");

#define pk printf(" ");

#define p(n) printf("%d",n);

#define pln(n) printf("%d\n",n);

#define s(n) scanf("%d",&n);

#define ss(n) scanf("%s",n);

#define ps(n) printf("%s",n);

#define sld(n) scanf("%lld",&n);

#define pld(n) printf("%lld",n);

#define slf(n) scanf("%lf",&n);

#define plf(n) printf("%lf",n);

#define sc(n) scanf("%c",&n);

#define pc(n) printf("%c",n);

#define gc getchar();

#define re(n,a) memset(n,a,sizeof(n));

#define len(a) strlen(a)

using namespace std;



#include <stdio.h>

#include <math.h>

#include <string.h>

#include <algorithm>

#include <iostream>

#include <string>

#include <time.h>

#include <queue>

#include <list>

#include <map>

#include <set>

#include <vector>

#include <stack>

#include <string.h>



#define sf scanf

#define pf printf

#define lf double

#define ll long long

#define p123 printf("123\n");

#define pn printf("\n");

#define pk printf(" ");

#define p(n) printf("%d",n);

#define pln(n) printf("%d\n",n);

#define s(n) scanf("%d",&n);

#define ss(n) scanf("%s",n);

#define ps(n) printf("%s",n);

#define sld(n) scanf("%lld",&n);

#define pld(n) printf("%lld",n);

#define slf(n) scanf("%lf",&n);

#define plf(n) printf("%lf",n);

#define sc(n) scanf("%c",&n);

#define pc(n) printf("%c",n);

#define gc getchar();

#define re(n,a) memset(n,a,sizeof(n));

#define len(a) strlen(a)

using namespace std;





/*

//快速幂 (a^b)%mod

//如果求逆元，则b = mod-2;

ll mod;

//

//快速幂 (a^b)%mod

//如果求逆元，则b = mod-2;

ll pow_quick(ll a,ll b){

    ll r = 1,base = a;

    while(b){

        if(b & 1){

            r *= base;

            r %= mod;

        }

        base *= base;

        base %= mod;

        b >>= 1;

    }

    return r;

}

//

struct A{

    ll op,x;

}a[100060];

int main(){

    int T = 0;

    s(T)

    ll q,m;

    for(ll i = 0; i< T; i ++) {

        //slf(ax) slf(ay) slf(bx) slf(by) slf(cx) slf(cy)

        sld(q) sld(mod)

        ll temp = 1;

        pf("Case #%d: ",i+1);

        for(ll j = 1;j <= q; j ++){

            sld(a[j].op) sld(a[j].x)

            if(a[j].op == 1){

                temp *= a[j].x;

                temp %=

                mod;

            }else if(a[j].op == 2){

                temp *= pow_quick(a[a[j].x].x,mod-2);

                temp %= mod;

            }

            pld(temp) pn

        }













        pn

    }



    return 0;

}

*/



#include       <set>

#include       <map>

#include     <queue>

#include     <cmath>

#include    <cstdio>

#include    <cctype>

#include    <vector>

#include   <cstring>

#include <algorithm>

using namespace std;





const ll mod = 1e9+7;

const double eps = 1e-7;

const ll maxn = 105;



ll fast_pow(ll a,ll b,ll mod){

    ll ans = 1;

    while(b){

        if(b&1)

            ans = ans*a%mod;

        a = a*a%mod;

        b>>=1;

    }

    return ans;

}



ll w[maxn], v[maxn];

ll dp[maxn*4][maxn];



int main(){

    ll n, W, c;

    scanf("%lld%lld",&n,&W);

    for(ll i=0;i<n;i++)

        scanf("%lld%lld",&w[i],&v[i]);

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

        w[i] -= w[0];

        w[i] ++;

    }

    c = w[0]-1;

    w[0] -= c;

    for(ll i=0;i<n;i++)

        for(ll j=n*4;j>=w[i];j--)

            for(ll k=1;k<=i+1;k++){

                    dp[j][k] = max(dp[j][k],dp[j-w[i]][k-1]+v[i]);

    }

    ll ans = 0;

    for(ll j=n*4;j>=0;j--)

        for(ll k=1;k<=n;k++){

            if(k*c+j<=W){

                ans = max(ans,dp[j][k]);

            }

        }

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

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 5.116603187659336x):
#include       <set>

#include       <map>

#include     <queue>

#include     <cmath>

#include    <cstdio>

#include    <cctype>

#include    <vector>

#include   <cstring>

#include <algorithm>

using namespace std;



typedef long long ll;

const ll mod = 1e9+7;

const double eps = 1e-7;

const int maxn = 105;



ll fast_pow(ll a,ll b,ll mod){

    ll ans = 1;

    while(b){

        if(b&1)

            ans = ans*a%mod;

        a = a*a%mod;

        b>>=1;

    }

    return ans;

}



int w[maxn], v[maxn];

int dp[maxn*4][maxn];



int main(){

    int n, W, c;

    scanf("%d%d",&n,&W);

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

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

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

        w[i] -= w[0]-1;

    c = w[0]-1;

    w[0] = 1;

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

        for(int j=n*4;j>=w[i];j--)

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

                dp[j][k] = max(dp[j][k],dp[j-w[i]][k-1]+v[i]);

    }

    int ans = 0;

    for(int j=n*4;j>=0;j--)

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

            if(1ll*k*c+j<=W){

                ans = max(ans,dp[j][k]);

            }

    }

    printf("%d\n",ans);

    return 0;

}