#include <iostream>
#include <stack>
#include <unordered_map>
using namespace std;
//定义一个包含两个数对的数对,分别代表第i个物品、选与不选、总重量、总价值。
typedef pair<pair<int, bool>,pair<int,int>>PII;
const int N = 110;
int n, m, res;
int v[N], w[N];
int bfs()
{
stack<PII>st;//将第i个物品的信息推入栈
st.push({ {1,true},{v[1],w[1]} }), st.push({ { 1,false } ,{0,0} });//初始推入第一个物品选还是不选
while (st.size())
{
auto t = st.top();
st.pop();
int ff = t.first.first, fs = t.first.second;
int sf = t.second.first, ss = t.second.second;
if (ff < n)//没到第n个物品,则考虑选与不选是否能够全部推入
{
//选择后依然未超过容积上线才能推入
if (sf + v[ff + 1] <= m)st.push({ {ff + 1,true} ,{sf + v[ff + 1],ss + w[ff + 1]} });
//不选择必然能推入
st.push({ {ff + 1,false} ,{sf,ss} });
}
if (ff == n)//判断所有第n层状态的最大值
res = max(res, ss);
}
return res;
}
int main()
{
cin >> n >> m;
for (int i = 1; i <= n; i++)scanf("%d%d", &v[i], &w[i]);
cout << bfs();
return 0;
}