#include <iostream>
using namespace std;
void fast_io()
{
ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
}
int main()
{
fast_io();
int m, n;
cin >> n >> m;
int p[n+1] = {0};
int w[n+1] = {0};
int v[n+1][m+1];
for (int i = 1; i < n+1; i++){
cin >> w[i] >> p[i];
}
for (int i = 0; i < n+1; i++){
for (int j = 0; j < m+1; j++){
v[i][j] = 0;
}
}
for (int i = 1; i < n+1; i++){
for (int j = 1; j < m+1; j++){
if (j-w[i] >= 0){
v[i][j] = max(v[i-1][j], v[i-1][j-w[i]]+p[i]);
}else{
v[i][j] = v[i-1][j];
}
}
}
int num = v[n][m];
int results[n+1] = {0};
for (int i = n; i >= 1; i--){
for (int j = m; j >= 1; j--){
if (v[i-1][j] == num){
break;
}
if (j == 1){
num -= p[i];
results[i] = 1;
}
}
}
int sum = 0;
for (int i = 0; i < n+1; i++){
if (results[i] == 0){continue;}
sum += p[i];
}
cout << sum << endl;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCnZvaWQgZmFzdF9pbygpCnsKICAgIGlvc19iYXNlOjpzeW5jX3dpdGhfc3RkaW8oZmFsc2UpLCBjaW4udGllKG51bGxwdHIpLCBjb3V0LnRpZShudWxscHRyKTsKfQoKaW50IG1haW4oKQp7CiAgICBmYXN0X2lvKCk7CiAgICBpbnQgbSwgbjsKICAgIGNpbiA+PiBuID4+IG07CiAgICBpbnQgcFtuKzFdID0gezB9OwogICAgaW50IHdbbisxXSA9IHswfTsKICAgIGludCB2W24rMV1bbSsxXTsKCiAgICBmb3IgKGludCBpID0gMTsgaSA8IG4rMTsgaSsrKXsKICAgICAgICBjaW4gPj4gd1tpXSA+PiBwW2ldOwogICAgfQoKICAgIGZvciAoaW50IGkgPSAwOyBpIDwgbisxOyBpKyspewogICAgICAgIGZvciAoaW50IGogPSAwOyBqIDwgbSsxOyBqKyspewogICAgICAgICAgICB2W2ldW2pdID0gMDsKICAgICAgICB9CiAgICB9CgogICAgZm9yIChpbnQgaSA9IDE7IGkgPCBuKzE7IGkrKyl7CiAgICAgICAgZm9yIChpbnQgaiA9IDE7IGogPCBtKzE7IGorKyl7CiAgICAgICAgICAgIGlmIChqLXdbaV0gPj0gMCl7CiAgICAgICAgICAgICAgICB2W2ldW2pdID0gbWF4KHZbaS0xXVtqXSwgdltpLTFdW2otd1tpXV0rcFtpXSk7CiAgICAgICAgICAgIH1lbHNlewogICAgICAgICAgICAgICAgdltpXVtqXSA9IHZbaS0xXVtqXTsKICAgICAgICAgICAgfQogICAgICAgIH0KICAgIH0KICAgIGludCBudW0gPSB2W25dW21dOwogICAgaW50IHJlc3VsdHNbbisxXSA9IHswfTsKICAgIGZvciAoaW50IGkgPSBuOyBpID49IDE7IGktLSl7CiAgICAgICAgZm9yIChpbnQgaiA9IG07IGogPj0gMTsgai0tKXsKICAgICAgICAgICAgaWYgKHZbaS0xXVtqXSA9PSBudW0pewogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKGogPT0gMSl7CiAgICAgICAgICAgICAgICBudW0gLT0gcFtpXTsKICAgICAgICAgICAgICAgIHJlc3VsdHNbaV0gPSAxOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgfQogICAgaW50IHN1bSA9IDA7CiAgICBmb3IgKGludCBpID0gMDsgaSA8IG4rMTsgaSsrKXsKICAgICAgICBpZiAocmVzdWx0c1tpXSA9PSAwKXtjb250aW51ZTt9CiAgICAgICAgc3VtICs9IHBbaV07CiAgICB9CiAgICBjb3V0IDw8IHN1bSA8PCBlbmRsOwp9