#include<bits/stdc++.h>
using namespace std;
int v[1005], w[1005];
int f[1005][1005];
int main(){
int N, V;
cin>>N>>V;
for(int i = 1; i <= N; i++) cin>>v[i]>>w[i];
for(int i = 1; i <= N; i++){
for(int j = 1; j <= V; j++){
f[i][j] = (j - v[i] >= 0) ? max(f[i-1][j-v[i]] + w[i], f[i-1][j]) : f[i-1][j];
}
}
cout<<f[N][V]<<endl;
return 0;
}