# include <bits/stdc++.h>


using namespace std;


map <int, int > d, t;
int n, m, a[101], b[101], mx;

int main(){
       scanf("%d %d", &n, &m);

       for(int  i = 1;i <= n;i ++){
              scanf("%d %d", &a[i], &b[i]);
       }
       for(int i = 1;i <= n;i ++)
       {
              t[a[i]] += b[i];
              for(auto it = d.begin(); it != d.end(); it ++){
                    int x = it -> first;
                    if(m - a[i] < x) continue;
                    t[a[i] + x] = max(t[a[i] + x], d[x] + b[i]);
              }
              for(auto it = t.begin(); it != t.end(); it ++){
                    int x = it->first;
                    d[x] = t[x];
                    if(x <= m)
                           mx = max(t[x], mx);
              }
       }
       cout << mx;
       return 0;
}
