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

long long dp[2][3003];

int main()
{

        long long n,m,a,b,c,d,e,f,g,h,p,q,r,fr,sc,tr,sz,tz,i,j,k,mx=LLONG_MIN,mn=LLONG_MAX;
        long long x=0,y=0,cnt=0,res=0,ttl=0,ans=0,sum=0; long long flg=0,flag=1,na=0,as=1;
        vector<long long>u,v,w; vector< pair<long long,long long> >vct; vector<string>vst;
        set<long long>st,nt,tt; map<long long,long long>mp,nq,qr; string str,ttr,ntr;

        scanf("%lld %lld",&n,&k);

        for(i=1;i<=n;i++)
        {
            scanf("%lld %lld",&a,&b); vct.push_back(make_pair(a,b));
        }


        sort(vct.begin(),vct.end());

        long long idx,cap;

        for(idx=n-1;idx>=0;idx--)
        {
            for(cap=1;cap<=k;cap++)
            {
                fr=idx%2; sc=(idx+1)%2; a=vct[idx].first; b=vct[idx].second;

                p=0; q=0;

                if(idx==n-1 || cap-a<=0){  p=b; }
                else{  p=b+dp[sc][cap-a];   }

                if(idx!=n-1){  q=dp[sc][cap];  }

                dp[fr][cap]=max(p,q);


            }
        }

        printf("%lld\n",dp[0][k]);








    return 0;
}




#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  int n, t;
  cin >> n >> t;
  vector<P> v(n);
  rep(i, 0, n) cin >> v[i].first >> v[i].second;
  sort(v.begin(), v.end());

  vector<vector<int>> dp(n + 1, vector<int>(3001, 0));
  int ans = 0;
  rep(i, 0, n) {
    rep(j, 0, t) {
      chmax(dp[i + 1][j], dp[i][j]);
      if (j + v[i].first < t)
        chmax(dp[i + 1][j + v[i].first], dp[i][j] + v[i].second);
    }
    int now = dp[i][t - 1] + v[i].second;
    chmax(ans, now);
  }

  cout << ans << endl;
}
