#include<bits/stdc++.h>
using namespace std;

int n,t;
vector<pair<int,int> >vec;
int mem[3002][3002];

int solve(int cur,int T)
{
    if(cur==n)return 0;
    if(T>=t)return 0;
    int &ret=mem[cur][T];
    if(ret!=-1)return ret;

    int x=solve(cur+1,T),y=0;
    y=solve(cur+1,T+vec[cur].first)+vec[cur].second;
    return ret=max(x,y);

}

int main()
{
    cin>>n>>t;
    int a,b;
    for(int i=0;i<n;i++)
    {
        cin>>a>>b;
        vec.push_back({a,b});
    }
    memset(mem,-1,sizeof(mem));
    sort(vec.begin(),vec.end());
    int ans=solve(0,0);
    cout<<ans<<endl;


    return 0;
}
