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

struct data {
  long long w, v;
};

long long n, w, b;
long long dp[105][105][3005] = {0};
vector<data> v;

long long solve();

int main() {
  cin >> n >> w;
  v.resize(n);
  for(int i = 0; i < n; ++i) cin >> v[i].w >> v[i].v;
  cout << solve() << endl;
  return 0;
}

long long solve() {
  b = v[0].w;
  long long ans = 0;
  for(long long i = 0; i < n; ++i)
    for(long long j = 1; j <= n; ++j)
      for(long long k = 0; k + j * b <= w && k <= n * 3;
          ++k) {
        long long now = v[i].w - b;
        dp[i + 1][j][k] = dp[i][j][k];
        if(k - now >= 0)
          dp[i + 1][j][k] =
              max(dp[i + 1][j][k],
                  dp[i][j - 1][k - now] + v[i].v);
        ans = max(ans, dp[i + 1][j][k]);
      }
  return ans;
}