#include <bits/stdc++.h>
using namespace std;

int main(){
    long int N, W;
    cin >> N >> W;
    vector<long int> v(N), w(N);
    long int w0;
    for (int i = 0; i < N; i++) {
        cin >> w[i] >> v[i];
        if (i == 0) w0 = w[0];
        w[i] -= w0;
    }
    vector<vector<long int>> dp(101, vector<long int>(300, 0)); 
    for (int i = 0; i < N; i++) {
        for (int j = i+1; j >= 1; j--) {
            for (int k = 0; k <= 3*N; k++) {
                if (k-w[i] >= 0) {
                    dp[j][k] = max(dp[j][k], dp[j-1][k-w[i]] + v[i]);
                }
            }
        }
    }
    long int ans = 0;
    for (int i = 0; i <= N; i++) {
        for (int j = 0; j <= 3*N; j++) {
            if (i*w0 + j <= W) ans = max(ans, dp[i][j]);
        }
    }
    
    cout << ans << endl;
   
}