// #define _GLIBCXX_DEBUG #include using namespace std; #include using namespace atcoder; using ll = long long; using vi = vector; using vvi = vector>; using pii = pair; #define rep(i, n) for (int i = 0; i < (int)(n); ++i) #define repr(i, n) for (int i = (int)(n - 1); i >= 0; --i) inline void chmax(int &a, int b) { if (b > a) a = b; } int main() { int n, I; cin >> n >> I; vi s(n), a(n); rep(i, n) cin >> s[i] >> a[i]; vi dp(I + 1, 0); rep(i, n) { repr(j, I - s[i] + 1) chmax(dp[j + s[i]], dp[j] + a[i]); } cout << dp[I] << endl; return 0; }