import std.stdio, std.string, std.array, std.conv, std.algorithm, std.typecons, std.range, std.container, std.math, std.algorithm.searching, std.functional,std.mathspecial, std.numeric;

void main(){
    auto nw=readln.split.array;
    auto W=nw[1].to!long;
    long[][]wvs;
    foreach(i;0..nw[0].to!int){
        auto wv=readln.split.map!(to!long).array;
        wvs~=wv;
    }
    auto w1=wvs[0][0];
    auto v0s=wvs.filter!(wv=>wv[0]==w1  ).map!(wv=>wv[1]).array;
    auto v1s=wvs.filter!(wv=>wv[0]==w1+1).map!(wv=>wv[1]).array;
    auto v2s=wvs.filter!(wv=>wv[0]==w1+2).map!(wv=>wv[1]).array;
    auto v3s=wvs.filter!(wv=>wv[0]==w1+3).map!(wv=>wv[1]).array;
    v0s.sort!"a>b"();
    v1s.sort!"a>b"();
    v2s.sort!"a>b"();
    v3s.sort!"a>b"();
    long result=0;
    foreach(i0;0..v0s.length+1)
    foreach(i1;0..v1s.length+1)
    foreach(i2;0..v2s.length+1)
    foreach(i3;0..v3s.length+1)
    {
        if(w1*i0+(w1+1)*i1+(w1+2)*i2+(w1+3)*i3>W)continue;
        auto chosen=v0s[0..i0]~v1s[0..i1]~v2s[0..i2]~v3s[0..i3];
        auto res=chosen.sum;
        result=max(result,res);
    }
    writeln(result);
}
