#include <bits/stdc++.h>
#define T int t;cin>>t;while(t--)
#define fast ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr)
#define ll long long
#define endl '\n'
using namespace std;
const ll N = 1e6 + 6;
ll n, q;
pair<ll, ll> pr[103];
ll dp[103][N];

ll napsake(ll i, ll k, ll sum) {
    if (k > q) return 0;
    if (i == n) return sum;
    if (dp[i][k] != (-1)) return dp[i][k];
    ll o1 = (-1);
    if (k + pr[i].first <= q) o1 = napsake(i + 1, k + pr[i].first, sum + pr[i].second);
    ll o2 = napsake(i + 1, k, sum);
    return dp[i][k] = max(o1, o2);
}

void Abady() {
    memset(dp, -1, sizeof(dp));
    cin >> n >> q;
    for (int i = 0; i < n; i++) {
        int a, b;
        cin >> a >> b;
        pr[i] = {a, b};
    }
    cout << napsake(0, 0, 0);
}

int main() {
    fast;
    Abady();
}
