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

// dfmt off
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;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue = BinaryHeap!(Array!long, "a<b");
// dfmt on

/// Number of k-combinations
T combination(T = long)(T n, T k)
{
    assert(0 <= k);
    assert(0 <= n);
    if (n < k)
        return 0;
    k = min(n - k, k);
    if (k == 0)
        return 1;
    if (k == 1)
        return n;
    return memoize!combination(n - 1, k - 1) + memoize!combination(n - 1, k);
}

void main()
{
    long N, W;
    scan(N, W);
    auto T = new long[][](4);
    long base;
    {
        long w, v;
        scan(w, v);
        base = w;
        T[w - base] ~= v;
    }
    foreach (_; 1 .. N)
    {
        long w, v;
        scan(w, v);
        T[w - base] ~= v;
    }
    foreach (i; 0 .. 4)
    {
        T[i].sort!"b<a"();
    }
    long ans;
    foreach (a; 0 .. T[0].length + 1)
        foreach (b; 0 .. T[1].length + 1)
            foreach (c; 0 .. T[2].length + 1)
            {
                long weight = a * (base + 0) + b * (base + 1) + c * (base + 2);
                if (W < weight)
                    continue;
                long value = T[0][0 .. a].sum() + T[1][0 .. b].sum() + T[2][0 .. c].sum();
                long i;
                while (i < T[3].length && value + T[3][i] <= W)
                    value += T[3][i++];
                ans = ans.max(value);
            }
    writeln(ans);
}
