import std.stdio, std.algorithm, std.conv, std.array, std.string;

long[100][100] TABLE;

void main()
{
    foreach (ref l; TABLE)
        foreach (ref c; TABLE)
            c = -1;

    int N;
    long W;
    long[101] ws;
    long[101] vs;

    readf("%d %d", &N, &W);
    foreach (i; 0..N) {
        readln;
        readf("%d %d", ws[i], vs[i]);
    }

    long solve(int i, long v_sp) {
        if (TABLE[i][v_sp] != -1) return TABLE[i][v_sp];

        long ret;
        if (i == N) {
            ret = 0;
        } else if (v_sp < ws[i]) {
            ret = solve(i+1, v_sp);
        } else {
            ret = max(solve(i+1, v_sp), solve(i+1, v_sp - ws[i]) + vs[i]);
        }

        return TABLE[i][v_sp] = ret;
    }

    writeln(solve(0, W));
}