#include <bits/stdc++.h>
using namespace std;
#define pb push_back
typedef long long int ll;
#define MOD 1000000007
#define INF 1e18
#include <ctime>
#define rep(i, x, n) for (ll i = x; i < n; i++)
#define rev(i, n, x) for (ll i = n; i > x; i--)
#define endl "\n"
#define all(c) (c).begin(), (c).end()
#define int long long int
#ifdef mishra
#define debug(x) cout << ">>" << #x << " is " << x << "<<" << endl;
#define print_time() cout << setprecision(6) << "time: " << (clock() - start) / (double)CLOCKS_PER_SEC << '\n';
#else
#define debug(x) ;
#define print_time() ;
#endif

clock_t start;
void FAST(ll argc)
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    start = clock();
    if (argc == 2)
        freopen("std.in", "r", stdin);
}

/*vector<ll> v;
void seive()
{
    v.pb(2);
    for (int i = 3; i < 100000; i += 2)
    {
        for (int j = 0; j < v.size(); j++)
        {
            if (i % v[j] == 0)
                break;
            if (v[j] * v[j] > i)
            {
                v.pb(i);
                break;
            }
        }
    }
}
/*
void prime_factor(ll x, vector<ll> &r)
{
    ll sqrt_x = sqrt(x);

    for (ll i : v)
    {
        if (i > sqrt_x)
            break;

        if (x % i == 0)
            r.pb(i);

        while (x % i == 0)
        {
            x /= i;
        }
    }

    if (x >= 2)
        r.pb(x);
}
*/
/*
ll power(ll x, ll y)
{
    ll res = 1;
    x = x % MOD;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % MOD;
        y = y >> 1;
        x = (x * x) % MOD;
    }
    return res;
}
*/
/*
inline void dfs(ll curr, ll prev)
{

    for (ll i : a[curr])
        if (i != prev)
            dfs(i, curr);
}
*/
/*
ll multi(ll a, ll b)
{
    return ((a * b) % MOD);
}
*/
//---------------------CODE STARTS HERE---------------------

signed main(char argc, char *argv[])
{
    FAST(argc);

    ll testcase = 1;
    //cin >> testcase;

    while (testcase--)
    {
        int n, w;
        cin >> n >> w;
        pair<int, int> a[n];
        rep(i, 0, n)
                cin >>
            a[i].first >> a[i].second;

        sort(a, a + n);
        // int z[w + 5] = {0};
        map<int, int> m;
        m[0] = 0;
        bool ck = 0;
        int ans = 0;
        rep(i, 0, n)
        {
            int x = a[i].first;
            int y = a[i].second;
            // z[x] = max(z[x], y);
            stack<pair<int, int> > st;
            for (auto it : m)
            {
                if (it.first + x > w)
                    continue;
                st.push(make_pair(it.first + x,max(it.second + y, m[it.first + x])));
            }
            while(st.empty()==0)
            {
                auto z= st.top();
                st.pop();
                m[z.first] = z.second;
                if(z.first<=w)
                ans = max(ans, z.second);
            }
        }
        // for(auto it:m)
        // {
        //     cout << " ";
        //     debug(it.first);
        // debug(it.second);
        // }
        cout << ans << endl;
        //--------??--------CLEAR VECTORS--------??--------
        m.clear();
    }

    //v.clear();
    print_time();
    return 0;
}

Measured memory_bytes: 8192