#include using namespace std; #ifdef _RUTHEN #include #else #define show(...) true #endif using ll = long long; #define rep(i, n) for (int i = 0; i < (n); i++) template using V = vector; int main() { ios::sync_with_stdio(false); cin.tie(0); int N, I; cin >> N >> I; V s(N), a(N); rep(i, N) cin >> s[i] >> a[i]; V dp(I + 1); rep(i, N) { for (int j = I - s[i]; j >= 0; j--) { dp[j + s[i]] = max(dp[j + s[i]], dp[j] + a[i]); } } int ans = *max_element(dp.begin(), dp.end()); cout << ans << '\n'; return 0; }