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

int N;
ll W;
vector<ll> weight, value;

ll knapsack(int i, ll w) {
    if (i == 0 || w == 0) return 0;

    ll res = knapsack(i - 1, w);
    if (weight[i] <= w)
        res = max(res, value[i] + knapsack(i - 1, w - weight[i]));

    return res;
}


int main() {
    cin >> N >> W;
    weight.resize(N + 1);
    value.resize(N + 1);

    for (int i = 1; i <= N; i++)
        cin >> weight[i] >> value[i];

    cout << knapsack(N, W) << "\n";
    return 0;
}
