// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

typedef long double ld;

typedef pair<ll,ll> P;

typedef pair<int,int> Pi;

#define rep(i, n) for (ll i = 0; i < n; i++)

#define FOR(i, a, b) for (ll i = a; i < b; i++)

#define fi first

#define se second

#define PI (acos(-1))



template<class T>

inline bool chmax(T &a, T b) {

    if(a < b) {

        a = b;

        return true;

    }

    return false;

}

template<class T>

inline bool chmin(T &a, T b) {

    if(a > b) {

        a = b;

        return true;

    }

    return false;

}

template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}

template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}

template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){

	int len=d.size();

	rep(i,len){

		s<<d[i];if(i<len-1) s<<" ";

	}

	return s;

}

template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){

	int len=d.size();

	rep(i,len){

		s<<d[i]<<endl;

	}

	return s;

}

template<typename T> ostream& operator<<(ostream& s,const set<T>& v){

	s<<"{ ";

	for(auto itr=v.begin();itr!=v.end();++itr) {

		if (itr!=v.begin()) {s<< ", ";}

		s<<(*itr);

	}

	s<<" }";

	return s;

}

template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){

	s<<"{"<<endl;

	for(auto itr=m.begin();itr!=m.end();++itr){

		s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;

	}

	s<<"}"<<endl;

	return s;

}



const ll mod=1e9+7;

const ll inf=1e15;



int main(){

  cin.tie(0);

  ios::sync_with_stdio(false);

  ll n,t;

  cin>>n>>t;

  vector<P> g(n);

  vector<ll> a(n),b(n);

  rep(i,n) cin>>g[i].fi>>g[i].se;

  sort(begin(g),end(g));

  //cout<<g<<endl;

  rep(i,n){

	  a[i]=g[i].fi;

	  b[i]=g[i].se;

  }

  vector<vector<ll>> dp(n+1,vector<ll>(t+5000,-1));

  rep(i,n+1) dp[i][0]=0;

  rep(i,n){

	  rep(j,t+5000){

		  chmax(dp[i+1][j],dp[i][j]);

		if(dp[i][j]==-1) continue;

		if(j<t) chmax(dp[i+1][j+a[i]],dp[i][j]+b[i]);

	  }

  }

	//cout<<dp<<endl;

	ll ans=0;

	rep(j,t+5000) chmax(ans,dp[n][j]);

	cout<<ans<<endl;

}

// Faster C++ solution for the same problem (measured speedup: 1.741455114156314x):
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

typedef long double ld;

typedef pair<ll,ll> P;

typedef pair<int,int> Pi;

#define rep(i, n) for (ll i = 0; i < n; i++)

#define FOR(i, a, b) for (ll i = a; i < b; i++)

#define fi first

#define se second

#define PI (acos(-1))



template<class T>

inline bool chmax(T &a, T b) {

    if(a < b) {

        a = b;

        return true;

    }

    return false;

}

template<class T>

inline bool chmin(T &a, T b) {

    if(a > b) {

        a = b;

        return true;

    }

    return false;

}

template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}

template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}

template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){

	int len=d.size();

	rep(i,len){

		s<<d[i];if(i<len-1) s<<" ";

	}

	return s;

}

template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){

	int len=d.size();

	rep(i,len){

		s<<d[i]<<endl;

	}

	return s;

}

template<typename T> ostream& operator<<(ostream& s,const set<T>& v){

	s<<"{ ";

	for(auto itr=v.begin();itr!=v.end();++itr) {

		if (itr!=v.begin()) {s<< ", ";}

		s<<(*itr);

	}

	s<<" }";

	return s;

}

template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){

	s<<"{"<<endl;

	for(auto itr=m.begin();itr!=m.end();++itr){

		s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;

	}

	s<<"}"<<endl;

	return s;

}



const ll mod=1e9+7;

const ll inf=1e15;



int main(){

	cin.tie(0);

	ios::sync_with_stdio(false);

	int n,t;

	cin>>n>>t;

	vector<Pi> g(n);

	rep(i,n) cin>>g[i].fi>>g[i].se;

	sort(begin(g),end(g));

	vector<int> a(n),b(n);

	rep(i,n){

		a[i]=g[i].fi;

		b[i]=g[i].se;

	}

	vector<vector<int>> dp(n+1,vector<int>(t+1,0));

	rep(i,n)rep(j,t+1){

		chmax(dp[i+1][j],dp[i][j]);

		if(j-a[i]>=0){

			chmax(dp[i+1][j],dp[i][j-a[i]]+b[i]);

		}

	}

	int ans=0;

	//cout<<dp<<endl;

	FOR(i,1,n){

		chmax(ans,dp[i][t-1]+b[i]);

	}

	cout<<ans<<endl;

}