#include using namespace std; int main () { int N, M; cin >> N >> M; vector dp(M, 0); for (int i = 0; i < N; i ++) { int s, a; cin >> s >> a; if (s > M) { continue; } for (int j = M; j >= s; j --) { dp[j] = max(dp[j], dp[j - s] + a); } for (int j = 1; j <= M; j ++) { dp[j] = max(dp[j], dp[j - 1]); } } int ans = 0; for (int d : dp) { ans = max(ans, d); } cout << ans << endl; }