#include <fstream>
#include <vector>
std::ifstream input ("ruscsac.in");
std::ofstream output ("ruscsac.out");
struct object {
int weight;
int profit;
};
int main () {
int n, maxWeight;
input >> n >> maxWeight;
std::vector<object> objectArr(n);
for (int i = 0; i < n; i++){
input >> objectArr[i].weight >> objectArr[i].weight;
}
//dpArr[i][w] = max profit at the i-th object with w max weight
std::vector<std::vector<int>> dp(n, std::vector<int>(maxWeight+1));
for (int w = 0; w <= maxWeight; w++){
dp[0][w] = 0;
}
for (int i = 1; i < n; i++){
for (int w = 0; w <= maxWeight; w++){
dp[i][w] = std::max(dp[i-1][w], (objectArr[i].profit + dp[i-1][w - objectArr[i].weight]));
}
}
output << dp[n][maxWeight];
return 0;
}