// code by - Sankalp Ranjan

#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define tc    \
    ll t;     \
    cin >> t; \
    while (t--)
#define arip(a)                 \
    for (int i = 0; i < n; i++) \
        cin >> a[i];
#define print(a)                \
    for (int i = 0; i < n; i++) \
        cout << a[i] << " ";

#define f(i, a, b) for (int i = a; i < b; i++)
#define fo(i, a, b, c) for (int i = a; i < b; i += c)
#define fr(i, a, b) for (int i = a; i >= b; i--)

#define pb push_back
#define pf push_front
#define popf pop_front
#define popb pop_back
#define mp make_pair

#define M 1000000007
#define PI 3.14159265
#define INF (ll)9e18

#define vll vector<ll>
#define vpll vector<pair<ll, ll>>
#define pll pair<ll, ll>

#define lcm(a, b) (a * b) / (__gcd(a, b))
#define swap(a, b) \
    a ^= b;        \
    b ^= a;        \
    a ^= b;
#define l_b(v, x) (lower_bound(v.begin(), v.end(), x) - v.begin())
#define u_b(v, x) (upper_bound(v.begin(), v.end(), x) - v.begin())
#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))
#define yes cout << "YES" << endl
#define no cout << "NO" << endl

template <typename T>
void read(T &x)
{
    cin >> x;
}
template <typename T, typename T0>
void read(T &x, T0 &y) { cin >> x >> y; }

template <typename T, typename T0, typename T1>
void read(T &x, T0 &y, T1 &z) { cin >> x >> y >> z; }

bool isPowerOfTwo(int x) { return x && (!(x & (x - 1))); }

int digits(int n)
{
    int x = floor(log10(n)) + 1;
    return x;
}

ll fact(ll n)
{
    if (n == 0)
        return 1;
    return n * fact(n - 1);
}

bool sortbysec(const pair<int, int> &a, const pair<int, int> &b)
{
    return (a.second < b.second);
}

vector<bool> sieve(1000000, true);
void sieve_er()
{
    sieve[0] = false;
    sieve[1] = false;
    for (ll i = 2; i * i <= 1000000; i++)
    {
        if (sieve[i] == true)
        {
            for (ll j = i * i; j < 1000000; j += i)
                sieve[j] = false;
        }
    }
}

vll vec;
void divisors(ll n)
{
    for (ll i = 1; i <= sqrt(n); i++)
    {
        if (n % i == 0)
        {

            if (n / i == i)
                vec.pb(i);
            else
            {
                vec.pb(i);
                vec.pb(n / i);
            }
        }
    }
}

ll total_divisors(ll n)
{
    ll c = 0;
    for (ll i = 1; i <= sqrt(n); i++)
    {
        if (n % i == 0)
        {
            if (n / i == i)
                c = c + 1;
            else
                c = c + 2;
        }
    }
    return c;
}

ll nCr(ll n, ll r)
{
    ll ans = 1;
    f(i, 0, r)
    {
        ans *= n - i;
        ans /= i + 1;
    }
    return ans;
}

ll power_m(ll a, ll b, ll m = M)
{
    a %= m;
    ll res = 1;
    while (b > 0)
    {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}

ll power(ll a, ll b)
{
    ll res = 1;
    while (b > 0)
    {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}
ll strTo(string s)
{
    stringstream tmp(s);
    ll x = 0;
    tmp >> x;

    return x;
}

string NoTo(ll n)
{
    ostringstream str1;
    str1 << n;
    string ans = str1.str();
    return ans;
}

int fun()
{
    return 0;
}

void start()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}
int n,w;
ll dp[102][100005];
ll knapsack(int wt[],int val[],int n,int w)
{
    if(n==0||w==0)return 0;
    if(dp[n][w]!=-1)return dp[n][w];
    if(wt[n-1]<=w)
    return dp[n][w]=max(val[n-1]+knapsack(wt,val,n-1,w-wt[n-1]),knapsack(wt,val,n-1,w));
    else return dp[n][w]=knapsack(wt,val,n-1,w);
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //start();
    cin>>n>>w;
    int wt[n],val[n];
    f(i,0,n)
    {
        cin>>wt[i]>>val[i];
    }
    memset(dp,-1,sizeof(dp));
    ll ans=knapsack(wt,val,n,w);
    cout<<ans<<endl;
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
    return 0;
}

Measured memory_bytes: 83624