#include <bits/stdc++.h>
#define int long long
using namespace std;
int W, n;
int v[100111];
int w[100111];
int maxValue(int W, int pos) {
if (W == 0 || pos == 0) {
return 0;
}
if (w[pos] > W) {
return maxValue(W, pos-1);
}
return max(maxValue(W, pos-1), v[pos] + maxValue(W - w[pos], pos-1));
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> W;
for (int i = 1; i <= n; i += 1) {
cin >> w[i] >> v[i];
}
cout << maxValue(W, n);
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiNkZWZpbmUgaW50IGxvbmcgbG9uZwoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCmludCBXLCBuOwppbnQgdlsxMDAxMTFdOwppbnQgd1sxMDAxMTFdOwoKaW50IG1heFZhbHVlKGludCBXLCBpbnQgcG9zKSB7CiAgICBpZiAoVyA9PSAwIHx8IHBvcyA9PSAwKSB7CiAgICAgICAgcmV0dXJuIDA7CiAgICB9CgogICAgaWYgKHdbcG9zXSA+IFcpIHsKICAgICAgICByZXR1cm4gbWF4VmFsdWUoVywgcG9zLTEpOwogICAgfQoKICAgIHJldHVybiBtYXgobWF4VmFsdWUoVywgcG9zLTEpLCB2W3Bvc10gKyBtYXhWYWx1ZShXIC0gd1twb3NdLCBwb3MtMSkpOwp9CgppbnQzMl90IG1haW4oKSB7CiAgICBpb3NfYmFzZTo6c3luY193aXRoX3N0ZGlvKGZhbHNlKTsKICAgIGNpbi50aWUoTlVMTCk7CgogICAgY2luID4+IG4gPj4gVzsKICAgIGZvciAoaW50IGkgPSAxOyBpIDw9IG47IGkgKz0gMSkgewogICAgICAgIGNpbiA+PiB3W2ldID4+IHZbaV07CiAgICB9CgogICAgY291dCA8PCBtYXhWYWx1ZShXLCBuKTsKCiAgICByZXR1cm4gMDsKfQ==