#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
#define MAXN 100000 + 100
#define ll long long int
ll N[MAXN];
ll w[200];
ll v[200];
ll n;
ll max_V;
int main()
{
    cin>>n>>max_V;
    for(int i = 0;i < n;++i)
        cin>>v[i]>>w[i];
    for(int i = 0;i < n;++i)
        for(int j = max_V;j >= v[i];--j)
            N[j] = max(N[j], N[j - v[i]] + w[i]);
    cout<<N[max_V]<<endl;

    return 0;
}
