///Bismillahir Rahmanir Rahim
#include "bits/stdc++.h"

#define                           ll                          long long
#define                           int                         ll
#define                           fi                          first
#define                           si                          second
#define                           mp                          make_pair
#define                           pb                          push_back
#define                           pi                          pair<ll,ll>
#define                           clr(x)                      memset(x,0,sizeof(x));
#define                           f(i,l,r)                    for(int i=l;i<=r;i++)
#define                           rf(i,r,l)                   for(int i=r;i>=l;i--)
#define                           done(i)                     cout<<"done = "<<i<<endl;
#define                           show(x,y)                   cout<<x<<" : ";for(auto z:y)cout<<z<<" ";cout<<endl;
#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

using namespace std;

const ll inf=1e18;
const int mod=1e9+7;
const int M=3005;
int n,t;
int dp[M][M];
int a[M],b[M];
vector<pi>vec;
int solve(int pos,int tym)
{
    if(pos>n)return 0;
    if(tym>=t)return 0;
    int &ret=dp[pos][tym];
    if(ret!=(-1))return ret;
    ret=solve(pos+1,tym);
    ret=max(ret,solve(pos+1,tym+a[pos])+b[pos]);
    return ret;
}
 main()

{
    fast
    memset(dp,-1,sizeof dp);
    cin>>n>>t;
    f(i,1,n)
    {
        cin>>a[i]>>b[i];
        vec.pb(mp(a[i],-b[i]));
    }
    sort(vec.begin(),vec.end());
    f(i,0,n-1)
    {
        a[i+1]=vec[i].fi;
        b[i+1]=-vec[i].si;
    }
    int ses=solve(1,0);
    cout<<ses<<endl;
    return 0;

}




































#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define SIZE 1005


ll N,M;
int min_dist[SIZE],pre_node[SIZE];
vector<int> G[SIZE];

vector<int> bfs(int start){

	vector<int> ret(N+1);

	for(int i = 0; i < N; i++){

		min_dist[i] = BIG_NUM;
		pre_node[i] = -1;
	}
	min_dist[start] = 0;

	queue<int> Q;
	Q.push(start);

	while(!Q.empty()){

		int node_id = Q.front();
		Q.pop();

		for(int i = 0; i < G[node_id].size(); i++){

			int next = G[node_id][i];
			if(min_dist[next] != BIG_NUM)continue;

			min_dist[next] = min_dist[node_id]+1;
			pre_node[next] = node_id;
			Q.push(next);
		}
	}

	int minimum = BIG_NUM,last_node = -1;

	for(int i = 0; i < N; i++){
		if(i == start)continue;

		for(int k = 0; k < G[i].size(); k++){
			if(G[i][k] == start){
				if(minimum > min_dist[i]){
					minimum = min_dist[i];
					last_node = i;
				}
			}
		}
	}

	if(last_node == -1)return ret;

	int tmp = last_node;
	ret.clear();

	while(tmp != -1){
		ret.push_back(tmp);
		tmp = pre_node[tmp];
	}

	return ret;
}


int main(){

	scanf("%lld %lld",&N,&M);


	int from,to;

	for(ll i = 0; i < M; i++){

		scanf("%d %d",&from,&to);
		from--;
		to--;

		G[from].push_back(to);
	}

	vector<int> ans(N+1);

	for(ll start = 0; start < N; start++){

		vector<int> work = bfs(start);

		if(work.size() < ans.size()){

			ans = work;
		}
	}

	if(ans.size() == N+1){

		printf("-1\n");
		return 0;

	}else{

		printf("%lld\n",ans.size());
		for(int i = 0; i < ans.size(); i++){

			printf("%d\n",ans[i]+1);
		}
	}

	return 0;
}
