#include #include #define rep(i,n) for(int i=0;i vi; typedef vector vl; typedef vector> vvi; typedef vector> vvl; typedef long double ld; typedef pair P; template ostream& operator<<(ostream& os, const static_modint& a) {os << a.val(); return os;} template ostream& operator<<(ostream& os, const dynamic_modint& a) {os << a.val(); return os;} template istream& operator>>(istream& is, static_modint& a) {long long x; is >> x; a = x; return is;} template istream& operator>>(istream& is, dynamic_modint& a) {long long x; is >> x; a = x; return is;} template istream& operator>>(istream& is, vector& v){int n = v.size(); assert(n > 0); rep(i, n) is >> v[i]; return is;} template ostream& operator<<(ostream& os, const pair& p){os << p.first << ' ' << p.second; return os;} template ostream& operator<<(ostream& os, const vector& v){int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "\n" : " "); return os;} template ostream& operator<<(ostream& os, const vector>& v){int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "\n" : ""); return os;} template ostream& operator<<(ostream& os, const set& se){for(T x : se) os << x << " "; os << "\n"; return os;} template ostream& operator<<(ostream& os, const unordered_set& se){for(T x : se) os << x << " "; os << "\n"; return os;} template ostream& operator<<(ostream& os, const atcoder::segtree& seg){int n = seg.max_right(0, [](S){return true;}); rep(i, n) os << seg.get(i) << (i == n - 1 ? "\n" : " "); return os;} template ostream& operator<<(ostream& os, const atcoder::lazy_segtree& seg){int n = seg.max_right(0, [](S){return true;}); rep(i, n) os << seg.get(i) << (i == n - 1 ? "\n" : " "); return os;} template void chmin(T& a, T b){a = min(a, b);} template void chmax(T& a, T b){a = max(a, b);} const int K = 10; int main(){ int N, M; cin >> N >> M; vector> hand; long long ans1 = 0; rep(i, N){ int C, D; cin >> C >> D; if(C == 0) ans1 += D; else hand.emplace_back(C, D); } sort(hand.rbegin(), hand.rend()); vector> dp(K + 1); for(int i = 0; i <= K; i++){ dp[i].resize((M >> i) + 1); } for(auto [C, D] : hand){ for(int i = K - 1; i >= 0; i--){ for(int j = int(dp[i].size()) - 1; j >= C; j--){ chmax(dp[i + 1][(j - C) / 2], dp[i][j] + D); } } } long long ans2 = 0; for(int i = 0; i <= K; i++) for(int j = 0; j <= int(dp[i].size()) - 1; j++) chmax(ans2, dp[i][j]); cout << ans1 + ans2 << "\n"; return 0; }