#include using namespace std; using ll = long long; const ll INF = 1001001001001001001LL; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, m; cin >> n >> m; vector> card; ll ans = 0; for (int i = 0; i < n; i++) { int c, d; cin >> c >> d; if (c == 0) { ans += d; continue; } card.emplace_back(c, d); } sort(card.rbegin(), card.rend()); vector> dp(11, vector(m + 1, -INF)); dp[0][0] = 0; for (auto [c, d] : card) { auto ndp = dp; int mul = 1 << 9; for (int p = 9; p >= 0; --p) { for (int nc = m - mul * c; nc >= 0; --nc) { ndp[p + 1][nc + mul * c] = max(ndp[p + 1][nc + mul * c], dp[p][nc] + d); } mul /= 2; } dp = ndp; } ll tmp = -INF; for (int i = 0; i < 10; i++) { tmp = max(*max_element(dp[i].begin(), dp[i].end()), tmp); } cout << ans + tmp << '\n'; return 0; }