#include <bits/stdc++.h>
using namespace std;
#define int long long
#define f first
#define s second
#define pb push_back
typedef vector<int> vi;
#define mod 1000000007
#define nos ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
int dp[3005][3005];
int n,t;
int happy(vector<pair<int,int>>&a,int pidx,int time)
{
    if(time>=t||pidx>=n)
    return 0;
    if(dp[pidx][time]!=-1)
    return dp[pidx][time];
    return dp[pidx][time]=max(a[pidx].s+happy(a,pidx+1,time+a[pidx].f),happy(a,pidx+1,time));
}
int32_t main() {
    nos;
    cin>>n>>t;
    vector<pair<int,int>>a(n);
    for(int i=0;i<n;i++)
    cin>>a[i].f>>a[i].s;
    sort(a.begin(),a.end());
    memset(dp,-1,sizeof(dp));
    cout<<max(a[0].s+happy(a,1,a[0].f),happy(a,1,0));
    return 0;
}

#include<bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; i++)
#define repo(i, n) for(int i=1; i<=n; i++)
#define INF 1001001001
#define INFll 100100100100100
// debug用
#define PrintVec(x) for (auto elementPrintVec: x) { cout << elementPrintVec << " "; } cout << endl;

using namespace std;
using ull = unsigned long long;
using ll = long long;
using P = pair<int, int>;
const int mod = 1000000007;

int dp[3005][3005];

int main(){
  int n, t;
  cin >> n >> t;
  vector<int> a(n);
  vector<int> b(n);
  vector<P> ab(n);
  rep(i, n){
    cin >> a[i] >> b[i];
    ab[i]=P(a[i], b[i]);
  }
  sort(ab.begin(), ab.end());
  rep(i, n){
    a[i]=ab[i].first;
    b[i]=ab[i].second;
  }
  rep(i, n){
    rep(j, t){
      if(j-a[i]<0){
        dp[i+1][j]=dp[i][j];
      } else {
        dp[i+1][j]=max(dp[i][j], dp[i][j-a[i]]+b[i]);
      }
    }
  }
  int ans=0;
  rep(i, n){
    ans=max(dp[i][t-1]+b[i], ans);
  }
  cout << ans << endl;
  return 0;
}
