#include<stdio.h>
#include<stdlib.h>
/*
int size[] = {9,10};
int value[] = {5,4};
*/
#define N (sizeof(size)/sizeof(size[0]))

#define MAX_M 200

int size[MAX_M];
int value[MAX_M];

int main(int argc, char **argv){
  int i,j;
  int m;
  int total[MAX_M];
  int choice[MAX_M];
  int repack_total;
  int k;
  int f;
  int goods_num;
  int front_choice[MAX_M];
  int tmp;

  /*
  if(argc != 2){
    fprintf(stderr,"usage:knapsack m\n");
    exit(1);
  }
  */

  if(!scanf("%d %d",&goods_num,&m)) exit(1);

  for(i = 0; i < goods_num; i++){
    if(!scanf("%d %d",&value[i],&size[i])) exit(1);
  }


  for(i = 0; i < goods_num; i++){
      for(j = goods_num-1; j > i; j--){

	if(size[j] < size[j-1] || (size[j] == size[j-1] && value[j] > value[j-1])){
	  tmp=size[j];
	  size[j]=size[j-1];
	  size[j-1]=tmp;

	  tmp=value[j];
	  value[j]=value[j-1];
	  value[j-1]=tmp;
	}
      }
    }

  /*  m = atoi(argv[1]);
  printf("size of knapsack is %d\n",m);
  if(m >= MAX_M){
    fprintf(stderr,"Size over\n");
    exit(1);
  }
  */

  for(i = 0; i <= m; i++){
    total[i] = 0;
    choice[i] = -1;
    front_choice[i] = -1;
  }

  for(i = 0; i < goods_num; i++){

    for(j = m; j >= size[i]; j--){
      f = 0;
      
/*
      for(k = j-size[i]; choice[k] >= 0; k -= size[choice[k]]){
	if(choice[k] == i){
	  f = 1;
	  break;
	}
      }
  */    

      if(!f){
	
	repack_total = total[j - size[i]] + value[i];
	
	if(repack_total > total[j]){
	  total[j] = repack_total;
	  choice[j] = i;
	}

      }
    
    }

    for(k = 0; k <= m; k++) front_choice[k] = choice[k];
    
    /*
    printf("i = %d\n",i);
    printf("total  = ");
    for(j = 0; j <= m; j++) printf("%2d ",total[j]);
    printf("\nchoice = ");
    for(j = 0; j <= m; j++) printf("%2d ",choice[j]);
    printf("\n");
    */
  }
  /*
  for(i = m; choice[i] >= 0; i -= size[choice[i]]){
    printf("\ngoods%d(size=%d, value=%d)",choice[i], size[choice[i]], value[choice[i]]);
    } 
  printf("\ntotal value = %d\n",total[m]);
  */
  printf("%d\n",total[m]);
  return 0;

}