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

bool comp(pair<ll, ll>&a, pair<ll,ll>& b) {
    auto [wa, va] = a;
    auto [wb, vb] = b;
    return ((double)va/wa > (double)vb/wb);
}

int main() {
    int N, W; cin >> N >> W;
    vector<pair<ll,ll>> items(N+1);
    for (int i = 1; i <= N; i++) {
        ll wi, vi; cin >> wi >> vi;
        items[i] = {wi, vi};
    }

    sort(items.begin() + 1, items.end(), comp);

    int item = 1, ans = 0;
    while (W > 0 && item <= N) {
        auto [w, v] = items[item++]; 
        if (W >= w) {
            W -= w;
            ans += v;
        }
    }

    cout << ans << endl;

    return 0;
}