#pragma GCC optimize ("O2")
#include<bits/stdc++.h>
#include <queue>
#include <cstring>

#define mp make_pair
#define pb push_back
#define p push

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define ll long long

#define getI(a) scanf("%d",&a)
#define getII(a, b) scanf("%d%d",&a,&b)
#define getIII(a, b, c) scanf("%d%d%d",&a,&b,&c)
#define getL(a) scanf("%lld",&a)
#define getLL(a, b) scanf("%lld%lld",&a,&b)
#define getLLL(a, b, c) scanf("%lld%lld%lld",&a,&b,&c)
#define BEND(c) (c).begin(),(c).end()
#define BEND2(c) (c).rbegin(),(c).rend()
#define fi first
#define se second
#define pi 3.1415926535897932384626
#define getS(a) scanf("%s",a)
#define pfi(a) printf("%d",a);
#define pfii(a, b) printf("%d%d",a,b);
#define pfl(a) printf("%lld",a);
#define pfll(a, b) printf("%lld%lld",a,b);
#define pfd(a) printf("%lf",a);
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);
#define endl "\n"
#define sag (sol|1)
//#define sol (root<<1)
#define ort (bas+son)/2
#define SIZE  ( int)(1e9 + 7)
#define MAXN (ll) ((1e5+5))
#define K 25
#define  ALPHABET_SIZE  26
#define N (int)(1e5+10)
#define int ll
using namespace std;

typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<long long> vl;
typedef vector<pair<int, int>> vpi;
typedef vector<pair<long long, long long>> vpl;
typedef pair<int, int> pii;
typedef pair <ll, ll> pll;
typedef vector<vi> graph ;


int n, C;
int value[100005], weight[100005];
int dp[100005];
signed main() {
    cin >> n >> C;

    for (int i = 1 ; i <= n ; i++) {
        cin >> weight[i] >> value[i];
    }

    for (int i = n ; i >= 1 ; i--) {
        for (int c = C ; c >= weight[i] ; c--) {
            // for (int c = weight[i] ; c <= C ; c++) {
            dp[c] = max(dp[c], dp[c - weight[i]] + value[i]);
        }
    }

    cout << dp[C] << endl;
}





/*
vi dp(MAXN,2);
vi vec(MAXN);
int main(){
    int n ;
    cin >>n;

    for (int i = 1; i <=n ; ++i)
        cin >> vec[i];

    for (int j = 2; j <=n ; ++j)
        for (int i = vec[j]; i <j    ; ++i)
            dp[j]=(dp[i]+dp[j])%SIZE;


    int res = 0;
    for (int k = 1; k <=n ; ++k)
        res=(dp[k]+res)%SIZE;

    cout <<res;
    return 0;
}



















/*
int binaryse(vi vec, int key){
    for(auto el : vec)cout << el <<" ";
    cout << endl;
    cout << "key:"<<key <<endl;
    int l = 0;
    int r = vec.size()-1;
    if(vec.size() == 0)return 0;

    while(l <=r-3){
        int mid= (l+r)/2;
        if(key <= vec[mid]){
            r= mid;
        }else{
            l = mid-1;
        }

    }
    int res =0;
    int tm =vec.size();
    for (int i = 0; i < min(3,tm) ; ++i) {
        if(vec[l+i] <= key)res=l;
    }
    return (res+1);

}
int dp [55][55];
int main(){
   int n , v;
   cin >> n>>v;
   vi vec(n);
    for (int i = 0; i <n ; ++i) {
        cin >> vec[i];
    }
    int gg ;
    cin >> gg;
    vvi days(n+1,vi());
    for (int l,r,f,j = 0; j <gg ; ++j) {
        cin >> l>>r>>f;
        for (int i = l; i <=r ; ++i)
            days[i].pb(f);

    }

    for (int k = 1; k <=n ; ++k) {
        sort(BEND(days[k]));
    }

    for (int i = 1; i <n+1 ; ++i) {
        for (int j = 1; j <days[i].size() ; ++j) {
            days[i][j] += days[i][j-1];
        }
    }
    int ans = 0;
    for (int m = 1; m <=n ; ++m) {
        int cc = binaryse(days[m],vec[m-1]-v);
        ans+=cc;
        cout << cc<<"-"<<endl;
    }

    cout << ans;




    return  0;
}

















/*
int main ( ) {
    int n;
    cin >> n;
    ll res = 0;
    vi vec;
    ll sum =0;
    for (int cur, i = 0; i < n; ++i) {
        cin >> cur;
        vec.pb(cur);
        sum +=cur;

    }
    //cout << sum <<endl;
    int tek =0;
    int cift = 0;
    int t =0;

    for (int j = 0; j <n ; ++j) {
        t = res;
        res+=vec[j]/2;
        if(vec[j]%2){
            if(cift %2 ==1)tek=0;
            //cout<<tek<<"\n";
            tek++;
            if(tek%2==0 and cift %2==0){
                //cout << j<<"\n";
                res++;

            }
            cift =0;
        }else{

            cift++;

        }
        cout << res-t<<" ";
        if (j %5 == 4)cout<<endl;
       // cout << tek<<" "<<cift<<endl;
    }

    cout << res;








    return 0;
}






/*
int main ( ){
    int n ;
    cin >>n ;
    ll res =0;
    vi vec;
    for (int cur , i = 0; i <n ; ++i) {
        cin >>cur;
        vec.pb(cur);

    }
    bool ctr =0;
    int ncift=0;
    bool ci =0;
    for (int j = 0; j <n ; ++j) {
        if(vec[j]%2 ){
            if(ctr==1  and ci == 1){
                res+=(vec[j]+1)/2;
                continue;
            }

        }
        if(j < n-1 and vec[j]%2==1 and vec[j+1] %2 ==1){
            res+=(vec[j]+vec[j+1])/2;
            //cout << res<<" ";
            j++;
        }else if(j < n-1 and vec[j]%2==1 and vec[j+1] %2 !=1){
            ctr =1;

        }else{
            ncift++;
            if(ncift==2){
               ci =1;
               ncift=0;
            }
            res+=vec[j]/2;
        }

    }
    cout << res;

    return 0;
}









/*


int main(){
    IOS
    int a,b,d;
    cin>>a>>b>>d;
    int tmp =0;
    int k ;
    cin >> k;
    tmp = k % d;
    bool ctr =0;
    ll sum =k;
    vi vec;
    for (int i = 0; i <a ; ++i) {
        for (int cur,j = 0; j <b ; ++j) {
            if(i == 0  and j == 0 )vec.pb(k);
           else{
                cin >> cur;
                sum+=k;
                if(cur % d != tmp ){
                    ctr=1;
                }
                vec.pb(cur);
           }



        }
    }
    sort(BEND(vec));
    if(ctr){
        cout << -1;
        return 0;
    }
    int mm =(a*b +1)/2;
    mm= vec[mm];
    int sonuc= 0;

    for (int l = 0; l <(a*b) ; ++l) {
        sonuc+=abs(vec[l]-mm)/d;

    }

    int sonuc2= 0;
    mm =(a*b +1)/2 -1 ;
    for (int l = 0; l <(a*b) ; ++l) {
        sonuc2+=abs(vec[l]-mm)/d;

    }
    sonuc =min(sonuc ,sonuc2);

    cout << sonuc;


    return 0;
}










/*
int main (){
   IOS
   int a,b;
   cin >>a>>b;
   vi vec(a);
    for (int i = 0; i <a ; ++i) {
        cin>>vec[i];
    }
    //sort(BEND(vec));
    int res =0;
    int son =2;
    for (int i = 0; i <a -2; ++i) {
            if(i+2 > son)break;
            for (int k = son; k <a ; ++k) {
                if(vec[i] + b < vec[k]){

                    cout << i<<" "<<k <<endl;
                    //res+=a-k;
                    son = k;
                    break;
                }else {
                 //   cout<<i<<"e"<<k<<endl;
                    res+=(k-i-1);}
            }
            son++;

    }
    cout << res;
    return 0;
}
 */

Measured memory_bytes: 1024