import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

long[100] WS, VS;
long[long][100] MEMO;

void main()
{
    auto nw = readln.split.to!(int[]);
    auto N = nw[0];
    auto W = nw[1];

    foreach (i; 0..N) {
        auto wv = readln.split.to!(long[]);
        WS[i] = wv[0];
        VS[i] = wv[1];
    }

    long solve(int i, long w) {
        if (i == N) return 0;
        if (w in MEMO[i]) return MEMO[i][w];
        return MEMO[i][w] = max(
            solve(i+1, w),
            w < WS[i] ? 0 : solve(i+1, w-WS[i]) + VS[i]
        );
    }

    writeln(solve(0, W));
}