/*
        Author: Arham_doshi
        @quote "Code like there's no tommorow!"
         ***************************************   UNAUTHORISED COPYING OF CODE PROHIBITED   **********************************
        */
        #include <bits/stdc++.h>
         
        #define int         long long
        #define double      long double
        #define pb          push_back
        #define pf          push_front
        #define pii         pair<int,int>
        #define vi          vector<int>
        #define vii         vector<pii>
        #define mi          map<int,int>
        #define mii         map<pii,int>
        #define all(a)      (a).begin(),(a).end()
        #define rall(a)     (a).rbegin(),(a).rend()
        #define x           first
        #define y           second
        #define sz(x)       (int)x.size()
        #define endl        '\n'
        #define hell        998244353 
        #define PI          3.141592653589
        #define bs(v,n)     binary_search(all((v)),(n))
        #define lb(v,n)     lower_bound(all((v)),(n))
        #define ub(v,n)     upper_bound(all((v)),(n))
        #define fo(i,l,u)   for(i=l;i<u;i++)
        #define rfo(i,l,u)  for(i=l;i>=u;i--)
        #define allfo(s)    for(auto it=(s).begin();it!=(s).end();it++)
        #define _init(b)     memset(b,-1,sizeof(b))
        #define _init0(b)     memset(b,0,sizeof(b))
        #define S            100005
        using namespace std;
         
        int gcd(int a, int b) {  if (a == 0)  return b; return gcd(b % a, a); }  
        bool mod(double a,double b) {return a/b - floor(a/b);}
         
        int occurs(vi v,int n){
        auto it=lb(v,n);auto it1=ub(v,n);int x=it1-it;return x;}
         
        int logb(int base, int x) {
            return (log(x) / log(base));
        }
         
         
       
         
         
         
        signed main()
        {
            ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
            int i,j,w,x,t,n,k,a,b;
            cin>>n>>w;
            int dp[n+1][100005];
            vii v;
            fo(i,0,n){
                cin>>a>>b;
                v.pb({a,b});
            }
            sort(all(v));
            
            _init0(dp);
           // fo(i,1,S)cout<<i%10<<" ";
            //cout<<endl;
            
            fo(i,1,n+1){
                a=v[i-1].x;
                b=v[i-1].y;
                fo(j,1,S) dp[i][j]=dp[i-1][j];
                dp[i][b]=a;
                
                fo(j,1,S){
                    
                    
                        if(dp[i-1][j]!=0){
                            dp[i][j]=min(dp[i][j],dp[i-1][j]);
                        }
                        
                    
                    
                    
                    if(dp[i-1][j]!=0&&j+b<S){
                        
                        
                        if(dp[i][j+b]==0){
                            
                            dp[i][j+b]=dp[i-1][j]+a;
                            if(dp[i-1][j]+a>w)dp[i][j+b]=0;
                            
                        }
                        else{
                            dp[i][j+b]=min(dp[i][j+b],dp[i-1][j]+a);
                            if(dp[i][j+b]>w) dp[i][j+b]=0;
                            
                        }
                        
                    }
                    
                    //cout<<dp[i][j]<<" ";
                    
                }
                //cout<<endl;
            }
            x=0;
            fo(i,0,S){
                if(dp[n][i]!=0){
                    x=i;
                }
            }
            cout<<x;
            
            
            return 0;
        }

Measured memory_bytes: 79232