#include using namespace std; using LL = long long; int dp[1001]; int main() { int N, I; cin >> N >> I; for (int i = 0; i <= I; i++) dp[i] = -1; dp[0] = 0; int s, a; for (int i = 0; i < N; i++) { cin >> s >> a; for (int j = I - s; j >= 0; j--) { if (dp[j] != -1) { dp[j + s] = max(dp[j + s], dp[j] + a); } } } int ans = 0; for (int i = I; i >= 0; i--) { ans = max(ans, dp[i]); } cout << ans << endl; }