#include<stdio.h>
#include<memory.h>
#define ll long long
#define maxn 105
int w[maxn],v[maxn];
ll dp[maxn][maxn];
ll max(ll a,ll b)
{
    return a>b?a:b;
}
ll f(int x,int ww)
{
    if(x==0) return 0;
    if(dp[x][ww]!=0) return dp[x][ww];
    ll a,b=0;
    a=f(x-1,ww);
    if(ww-w[x]>=0) b=f(x-1,ww-w[x])+v[x];
    dp[x][ww]=max(a,b);
    return dp[x][ww];
}
int main()
{
    int n,W;
    while(~scanf("%d %d",&n,&W))
    {
        memset(dp,0,sizeof(dp));
        int i;
        for(i=1;i<=n;i++)
        {
            scanf("%d %d",&w[i],&v[i]);
        }
        ll res=f(n,W);
        printf("%lld\n",res);
    }
}
