#include <bits/stdc++.h>
#define int long long
using namespace std;
int dp[111][100111];
int W, n;
int v[100111];
int w[100111];
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];
}
for (int i = 1; i <= n; i += 1) {
for (int j = 0; j <= W; j += 1) {
if (w[i] > j) {
dp[i][j] = dp[i-1][j];
} else {
dp[i][j] = max(dp[i-1][j], v[i] + dp[i-1][j-w[i]]);
}
}
}
cout << dp[n][W];
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiNkZWZpbmUgaW50IGxvbmcgbG9uZwoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCmludCBkcFsxMTFdWzEwMDExMV07CmludCBXLCBuOwppbnQgdlsxMDAxMTFdOwppbnQgd1sxMDAxMTFdOwoKaW50MzJfdCBtYWluKCkgewogICAgaW9zX2Jhc2U6OnN5bmNfd2l0aF9zdGRpbyhmYWxzZSk7CiAgICBjaW4udGllKE5VTEwpOwoKICAgIGNpbiA+PiBuID4+IFc7CiAgICBmb3IgKGludCBpID0gMTsgaSA8PSBuOyBpICs9IDEpIHsKICAgICAgICBjaW4gPj4gd1tpXSA+PiB2W2ldOwogICAgfQoKICAgIGZvciAoaW50IGkgPSAxOyBpIDw9IG47IGkgKz0gMSkgewogICAgICAgIGZvciAoaW50IGogPSAwOyBqIDw9IFc7IGogKz0gMSkgewogICAgICAgICAgICBpZiAod1tpXSA+IGopIHsKICAgICAgICAgICAgICAgIGRwW2ldW2pdID0gZHBbaS0xXVtqXTsKICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgIGRwW2ldW2pdID0gbWF4KGRwW2ktMV1bal0sIHZbaV0gKyBkcFtpLTFdW2otd1tpXV0pOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgfQoKICAgIGNvdXQgPDwgZHBbbl1bV107CgogICAgcmV0dXJuIDA7Cn0=