import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop;


void main() {
  auto s = readln.split.map!(to!int);
  auto N = s[0];
  auto W = s[1];
  auto K = N.iota.map!(_ => readln.split.map!(to!int).array).array;
  K.sort!"a[1] < b[1]"();
  auto dp = new int[][](N, W+1);
  foreach (i; 0..W+1) dp[0][i] = (K[0][1] <= i) ? K[0][0] : 0;

  foreach (i; 1..N)
    foreach (w; 0..W+1) {
      if (w - K[i][1] >= 0)
        dp[i][w] = dp[i-1][w-K[i][1]] + K[i][0];
      dp[i][w] = max(dp[i-1][w], dp[i][w]);
    }

  dp[N-1][W].writeln;
}