//                                                                                                         
//                    |    |                    |         ,---.     o               |    
//,---.,---.,---.,---.|---.|__/ ,---.,---.,---.' ,---.    `---.,---..,---.,---.,---.|--- 
//|---'|   ||    |   ||   ||  \ ,---||   |,---|  `---.        ||   |||   ||   ||---'|     
//`---'|---'`---'`   '`   '`   ``---^|---'`---^  `---'    `---'`   '`|---'|---'`---'`---'
//     |                             |                               |    |   
//								.    , '|      /|
//								|    |  |     / |
//								 \  /   |    /__|_ 
//								  `'    | o     |
//      Version 1.4 patchnotes{
//			New Feature: Dying for the river flowing
//			New defines: finding the max and min of three integers
//			New Poetry: Rose,violet
//			New quotes: Russian proverb
//			Bug fixes
//		}        
//
//In the name of Allah the beneficent, the merciful
//Here the Special Forces come
//I know a thing and it is that I dont know nothing
//One day all turks will be gone crazy, then god bless you
//There's no ugly women, there's less vodka
//Sub to Mcan
//
//█▀█─█──█──█▀█─█─█
//█▄█─█──█──█▄█─█▄█
//█─█─█▄─█▄─█─█─█─█
//
//_______________%%%%%%%%%%%%%%__________________________________
//_____________%%%%%%%%%%%%%%%%%_________________________________
//____________%%%%%%%%%%%%%%%%%%%________________________________
//__________%%%%%%%%%%%%%%%%%%%%%%%______________________________
//__________%%%%%%%%%%%%%%%%%%%%%%%%_____________________________
//________%%%%%%%%%%%%%%%_____%%%%%%%____________________________
//________%%%%%%%%%%%%___________%%%%____________________________
//_______%%%%%%%%%%%%_____________%%%%___________________________
//_______%%%%%%%%%%%_______________%%%___________________________
//______%%%%%%%%%%%_________________%%%_____%%___________________
//______%%%%%%%%%%__________________________%%%__________________
//______%%%%%%%%%___________________________%%%__________________
//_____%%%%%%%%%%___________________________%%%%_________________
//_____%%%%%%%%%____________________________%%%%%%%%%%%%_________
//_____%%%%%%%%%___________________________%%%%%%%%%%%___________
//_____%%%%%%%%%_________________________%%%%%%%%%%%%____________
//_____%%%%%%%%%_______________________%%%%%%%%%%%%%_____________
//_____%%%%%%%%%_____________________%%%%%%%%%%%%%%%_____________
//_____%%%%%%%%%_________________________%%%%%%%%%%%_____________
//_____%%%%%%%%%___________________________%%%%%%%%%%____________
//_____%%%%%%%%%%___________________________%%%%%%%%%%___________
//______%%%%%%%%%___________________________%%%%%%%%%%___________
//______%%%%%%%%%___________________________%%%%____%%%__________
//_______%%%%%%%%%__________________________%%%_______%%_________
//_______%%%%%%%%%%_________________%_______%%__________%________
//________%%%%%%%%%%_______________%%_______%____________________
//________%%%%%%%%%%%_____________%%%____________________________
//_________%%%%%%%%%%%%%________%%%%_____________________________
//__________%%%%%%%%%%%%%%%%%%%%%%%______________________________
//___________%%%%%%%%%%%%%%%%%%%%%_______________________________
//____________%%%%%%%%%%%%%%%%%%%________________________________
//_____________%%%%%%%%%%%%%%%%%_________________________________
//______________%%%%%%%%%%%%%%%__________________________________
//_______________%%%%%%%%%%%%%___________________________________
//__________________%%%%%%%%_____________________________________
// _   __, _ __,   __,  _, __,   , _  _, _,_ __,   __, _ _,_ __, __,   __, _,   _, _  _ _ _, _  _,
// |   | \ | |_    |_  / \ |_)   \ | / \ | | |_)   |_) | | / |_  |_)   |_  |   / \ |  | | |\ | / _
// |   |_/ | |_    |   \ / | \    \| \ / |_| | \   | \ | |/  |   | \   |   | , \ / |/\| | | \| \ /
// ~   ~   ~ ~~~   ~    ~  ~ ~     )  ~  `~' ~ ~   ~ ~ ~ ~   ~~~ ~ ~   ~   ~~~  ~  ~  ~ ~ ~  ~  ~ 
//                                ~'                                                              
//
//        ⣠⣶⣾⣿⣿⢶⣶⡶⠦
//⠀⠀⠀⠀⠀⢀⣾⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⢢
//⠀⠀⠀⠀⠀⢸⣿⡏⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⡄

//⠀⠀⠀⠀⠀⢸⣿⠃⠀⢀⣠⣶⡆⢠⣶⣖⣻⣎⡇

//⠀⠀⠀⠀⠀⠁⡜⡄⠀⠉⠝⠋⠁⠘⣿⢿⡿⣳⠁

//⠀⠀⠀⠀⠀⠀⠀⣆⠀⠀⡠⠫⢤⣠⣿⡆⢘⡏

//⠀⠀⠀⠀⠀⠀⠀⣿⣦⡀⢧⣷⣬⢿⣽⣿⣾⠃

//⠀⠀⠀⢀⣴⣇⠙⣿⣿⣏⠚⠻⢿⣻⡿⠁

//⣤⣴⣶⣿⣿⣿⣿⣆⠈⠙⢿⣷⣾⣾⡿⣤⣤⣀

//⣿⣿⣿⣿⣿⣿⣿⣿⣆⠀⠀⠙⢿⠟⠁⣿⣿⣿⣿⣶⣄⡀

//⣿⣿⣿⣿⣿⣿⣿⣿⣿⣆⠀⣠⣾⣦⡀⠸⣿⣿⣿⣿⣿⣿⣧

//⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣆⠈⣿⣿⠃⠀⢿⣷⣿⣿⣿⣿⣿
//
//  __                                                             
// /  |                                                           |
//(___| ___  ___  ___  ___       ___  ___  ___       ___  ___  ___|
//|\   |   )|___ |___)|___      |   )|   )|___)     |   )|___)|   )
//| \  |__/  __/ |__   __/      |__/||    |__       |    |__  |__/ 
//                                                                 
//                                                                       
//|    |      /      /                                  /    /          
//(    )   ___ (  ___ (___  ___       ___  ___  ___      (___ (       ___ 
// \  /| |   )| |___)|    |___      |   )|   )|___)     |   )| |   )|___)
//  \/ | |__/ | |__  |__   __/      |__/||    |__       |__/ | |__/ |__  
//                                                                       
//
//  __                                                                                  __                  
// /|  /                   /                 /                                         /  |      /          
//( | (___  ___  ___  ___     ___       ___ (       ___       ___       ___  ___      (___| ___    ___  ___ 
//  | |   )|___)|   )|___)   |___      |   )| |   )|   )\   )|___      |   )|   )     |   )|___ | |   )|   )
//  | |  / |__  |    |__      __/      |__/|| |/\/ |__/| \_/  __/      |__/||  /      |  /  __/ | |__/||  / 
//                                                       /                                                 
//
//  __                                                                       
//|/  |      /    /                   /    /                                 
//|___| ___ (___ (___  ___  ___      (___ (___  ___  ___            ___      
//|   )|___)|    |    |___)|   )     |    |   )|   )|   )     \   )|   )|   )
//|__/ |__  |__  |__  |__  |         |__  |  / |__/||  /       \_/ |__/ |__/ 
//                                                             /            

//"Insert Problem name and code here"
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <queue>
using namespace std;
#define ll long long
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define ii pair<int,int>
#define nl '\n'
#define max3(a, b, c) max(a, b) > max(b, c) ? max(a, b) : max(b, c)
#define min3(a, b, c) min(a, b) < min(b, c) ? min(a, b) : min(b, c)
#define fillar(x) for(int i=0;i<x;i++)cin>>ar[i]
#define qquery int query;cin>>query;while(query--)
#define benfero freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
ll dp[101][100005];
ll ar[100005];
ll w[100005];

int main(){
ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	//benfero
	int n,m;
	cin>>n>>m;
	for(int i=0;i<n;i++){
		cin>>w[i]>>ar[i];
	}
	dp[0][w[0]-1]=ar[0];
	for(int i=0;i<n;i++){
		if(i!=0)
			dp[i][w[i]-1]=max(dp[i-1][w[i]],ar[i]);
		for(int j=0;j<m&&i!=0;j++){
			if(dp[i-1][j]){
				if(j+w[i]<m)
					dp[i][j+w[i]]=max(dp[i-1][j],dp[i-1][j]+ar[i]);
			}
			dp[i][j]=max(dp[i-1][j],dp[i][j]);
		}
	}
	/*for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			cout<<dp[i][j]<<' ';
		}
		cout<<nl;
	}*/
	ll max=0;
	for(int i=0;i<m;i++){
		if(max<dp[n-1][i])max=dp[n-1][i];
	}
	cout<<max;
}

Measured memory_bytes: 78080