#include int main() { using namespace std; unsigned long N, I; cin >> N >> I; vector> ans(I + 1); ans[0] = 0; for(unsigned long i{}, s, a; i < N; ++i){ cin >> s >> a; for(unsigned long j{I}; j >= s; --j)if(ans[j - s])ans[j] = max(ans[j].value_or(0), a + ans[j - s].value()); } cout << max_element(begin(ans), end(ans)) -> value() << endl; return 0; }