#include // #include // #include using namespace std; // using namespace atcoder; // using bint = boost::multiprecision::cpp_int; using ll = long long; using ull = unsigned long long; using P = pair; #define rep(i,n) for(ll i = 0;i < (ll)n;i++) #define ALL(x) (x).begin(),(x).end() #define MOD 1000000007 // #define MOD 998244353 int main(){ int n,I; cin >> n >> I; vector

v(n); rep(i,n)cin >> v[i].first >> v[i].second; vector dp(I+1,-MOD); dp[0] = 0; rep(i,n){ vector DP(I+1,-MOD); rep(j,I+1){ if(j+v[i].first <= I)DP[j+v[i].first] = max(DP[j+v[i].first],dp[j] + v[i].second); DP[j] = max(DP[j],dp[j]); } swap(dp,DP); } cout << *max_element(ALL(dp)) << "\n"; return 0; }