#include<bits/stdc++.h>
using namespace std;
int t, n, s[13000][13000];
vector<pair<int, int>> v(1);
int dfs(int now, int wei){
if(s[now][wei])
return s[now][wei];
if(now > n)
return 0;
else if(wei >= v[now].first)
return s[now][wei] = max(dfs(now + 1, wei - v[now].first) + v[now].second, dfs(now + 1, wei));
else
return 0;
}signed main(){
scanf("%d%d", &n, &t);
for(int i = 1; i <= n; ++i){
pair<int, int> p;
scanf("%d%d", &p.first, &p.second);
v.push_back(p);
}sort(v.begin(), v.end());
printf("%d", dfs(1, t));
return 0;
}