#include<bits/stdc++.h>
using namespace std;
int M,T,n,dp[10000010];
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>n>>M;
for(int i=1;i<=n;i++){
int m,p;
cin>>m>>p;
for(int j=M;j>=m;j--){
dp[j]=max(dp[j],dp[j-m]+p);
}
}
cout<<dp[M]<<'\n';
return 0;
}