#include <iostream>
#include<stdio.h>
#include<string.h>
#define maxn 100010
#define ll long long
using namespace std;

int w[maxn];
ll v[maxn],dp[maxn];
int n,ww;

inline ll read()//快读
{
    register ll x=0,f=1;register char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9')x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
    return x*f;
}

int main()
{
    scanf("%d%d",&n,&ww);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&w[i]);
        v[i]=read();
    }
    for(int i=1;i<=n;i++)
    {
        for(int j=ww;j>=w[i];j--)
            dp[j]=max(dp[j],1ll*dp[j-w[i]]+v[i]);
    }
    printf("%lld\n",dp[ww]);
    return 0;
}
