#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;
}