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

alias sread = () => readln.chomp();
ulong MOD = 1_000_000_007;
ulong INF = 1_000_000_000_000;
alias Goods = Tuple!(long, "w", long, "v");

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}

auto dp = new long[][](110, 100_100);
void main()
{
    long N, W;
    scan(N, W);
    auto goods = new Goods[](N);
    foreach (i; iota(N))
    {
        long w, v;
        scan(w, v);
        goods[i] = Goods(w, v);
    }
    foreach (i; iota(N))
    {
        foreach (j; iota(W))
        {
            dp[i + 1][j] = max(dp[i][j], dp[i + 1][j]);
            if (j + goods[i].w <= W)
            {
                dp[i + 1][j + goods[i].w] = dp[i][j] + goods[i].v;
            }
            // dp[i + 1].take(W + 1).writeln();
        }
    }
    // foreach (i, e; dp)
    // {
    //     if (i < N)
    //         e.take(W).writeln();
    // }
    dp[N].take(W + 1).reduce!(max).writeln();
}
