#include <iostream>
using namespace std;
const int N = 1010;
int weight[N], value[N], f[N];
int main(){
int n, bag;
cin >> n >> bag;
for(int i = 1; i <= n; i ++) cin >> weight[i] >> value[i];
for(int i = 1; i <= n; i ++ ){
for(int j = weight[i]; j <= bag; j ++ ){
f[j] = max(f[j], f[j - weight[i]] + value[i]);
}
}
cout << f[bag] << endl;
return 0;
}