#include <stdio.h>
#include <stdlib.h>
#define WMAX 10000
#define NMAX 100
int M[NMAX+1][WMAX+1];
int W[NMAX+1];
int V[NMAX+1];



int maxv(int a, int b){

  if(a > b)
   return a;


 return b;
}

int knapsack(int v, int w){


  if(w == 0 || v == 0){
    return 0;
  }

  M[v-1][w] = knapsack(v-1, w);
 if(w-W[v] >= 0){
  M[v-1][w-W[v]] = knapsack(v-1, w-W[v]);
  return maxv(M[v-1][w-W[v]] + V[v], M[v-1][w]);
 }

 return M[v-1][w];
}

int main(){
int q, p;
int count = 0;
 scanf("%d", &q);
 scanf("%d", &p);


  for(count; count < q; count++){
   scanf("%d %d", &V[count+1], &W[count+1]);
  }

  printf("%d\n", knapsack(q, p));
 return 0;
}