#include <iostream>
using namespace std;
typedef long long int ll;
ll v[1000];
ll w[1000];

ll mem[1000][100005];
ll Knapsack(ll i,ll j){
    if (i == 0 || j == 0) return 0;
    else if ( j >= w[i-1]){
        mem[i][j] = max(Knapsack(i-1,j),Knapsack(i-1,j-w[i-1])+v[i-1]);
    }
    else{
        mem[i][j] =  Knapsack(i-1,j);
    }
    return mem[i][j];
}

int main(){
    ll n,w2;
    cin >> n >> w2;
    for (ll i=0;i<n;i++) cin >> w[i] >> v[i];
    cout << Knapsack(n,w2);
    return 0;
}