#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); } } cout << dp[M] << endl; }