var readline = require('readline');

var knapSack = async function(){
  let n,capacity;

  let val = []
  let weight = [];

  const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
    terminal: false
  });

  async function processLineByLine() {
    const rl1 = readline.createInterface({
      input: process.stdin,
      output: process.stdout,
      terminal: false
    });
    let index = 0;
    for await (const line of rl1) {
      let [one, two] = line.trim().split(" ").map(x => parseInt(x));
      if(!index){
        [n,capacity] = [one,two]
      } else {
        weight.push(one);
        val.push(two);
        // console.log(val);
      }
      index++;
      if(index === n+1){
        return;
      }
    }
  }

  await processLineByLine();

  let mem = [];

  for(let i = 0 ; i <= capacity ; i++){
    mem.push(0);
  }

  for(let i=1;i<= n ; i++){
    for(let j=capacity;j > 0;j--){
      let valWithoutItem = mem[j];
      let valWithItem = 0;
      if(weight[i-1] <= j){
        valWithItem = val[i-1] + mem[j - weight[i-1]];
      }
      mem[j] = Math.max(valWithItem, valWithoutItem);
    }
  }

  console.log(mem[capacity]);
};

knapSack();
