function Main(s) {
  var s = s.split("\n");
  var n = s[0].split(" ")[0]*1, w = s[0].split(" ")[1]*1;
  var w_v = [[0, 0]].concat(s.slice(1, n + 1).map(e => e.split(" ").map(e => e*1)));
  var dp = new Array(n + 1);
  for (var i = 0; i < n + 1; i++) {
    dp[i] = new Array(w + 1).fill(0);
  }
  for (var i = 1; i <= n; i++) {
    for (var j = 1; j <= w; j++) {
      if (j - w_v[i][0] >= 0) {
        dp[i][j] = Math.max(dp[i][j], dp[i-1][j - w_v[i][0]] + w_v[i][1]);
      }
      dp[i][j] = Math.max(dp[i][j], dp[i-1][j]);
    }
  }
  console.log(dp[n][w]);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));