#include using namespace std; int main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); int N,M; cin >> N >> M; vector> CD(N); for(auto &[c,d] : CD) cin >> c >> d; sort(CD.rbegin(),CD.rend()); long long add = 0; while(CD.size()){ auto [c,d] = CD.back(); if(c == 0) add += d,CD.pop_back(); else break; } long long inf = 1e18; vector dp(M+1,add); for(auto [c,d] : CD){ for(int i=c; i<=M; i++) dp.at((i-c)>>1) = max(dp.at((i-c)>>1),dp.at(i)+d); } cout << dp.at(0) << endl; }