#include <fstream>
#include <vector>
using namespace std;
struct object{
int c, g;
}aux;
vector<object> v;
int n, t;
int r[2][10000];
void read()
{
ifstream fin ("rucsac.in");
fin >> n >> t;
v.push_back(aux);
for(int i = 1; i <= n; ++i){
fin >> aux.g >> aux.c;
v.push_back(aux);
}
fin.close();
}
int max(int x, int y)
{
return (x > y ? x : y);
}
void solve()
{
for (int i = 1; i <= n; ++i){
for (int j = 0; j <= t; ++j)
if(v[i].g <= j)
r[1][j] = max(r[0][j-v[i].g] + v[i].c, r[0][j]);
else r[1][j] = r[0][j];
for (int j = 0; j <= t; ++j)
r[0][j] = r[1][j];
}
}
void write()
{
ofstream fout ("rucsac.out");
fout << r[0][t] << "\n";
fout.close();
}
int main()
{
read();
solve();
write();
return 0;
}