#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#define Bug cout << "here\n";
using namespace std;
const int N = 3450;
int bag[12885];
int w[N], v[N];
int get_max(int a, int b) {
return a > b ? a : b;
}
int main() {
int i, k, n, m;
cin >> n >> m;
for(i = 1; i <= n; i++) {
cin >> w[i] >> v[i];
}
memset(bag, 0, sizeof(bag));
for(i = 1; i <= n; i++) {
for(k = m; k >= w[i]; k--) {
bag[k] = get_max(bag[k], bag[k-w[i]] + v[i]);
} /// bag[i][j] = get_min(bag[i-1][j], bag[i-1][j-w[i]]+v[i]);
}
cout << bag[m] << endl;
return 0;
}