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

enum inf3 = 1_001_001_001;
enum inf6 = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;


void main() {
    int n, c;
    scan(n, c);

    auto w = new int[](n);
    auto v = new long[](n);

    foreach (i ; 0 .. n) {
        scan(w[i], v[i]);
    }

    auto b = w[0];
    w[] -= w[0];

    auto dp = new long[][][](n + 1, n + 1, 3*n + 1);
    fillAll(dp, -inf6);
    foreach (wi ; 0 .. 3*n + 1) {
        dp[0][0][wi] = 0;
    }

    foreach (i ; 0 .. n) {
        foreach (j ; 0 .. n) {
            foreach (wi ; 0 .. 3*n + 1) {
                if (dp[i][j][wi] == -inf6) continue;
                dp[i + 1][j][wi] = max(dp[i + 1][j][wi], dp[i][j][wi]);
                if (wi + w[i] <= 3*n) {
                    dp[i + 1][j + 1][wi + w[i]] = max(dp[i + 1][j + 1][wi + w[i]], dp[i][j][wi] + v[i]);
                }
                
            }
        }
    }

    long ans;
    foreach (j ; 1 .. n + 1) {
        foreach (wi ; 0 .. 3*n + 1) {
            if (1L * b * j + wi > c) break;
            ans = max(ans, dp[n][j][wi]);
        }
    }
    writeln(ans);
}









void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}
