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

void main(){
    int N, W, vi, wi;
    readVars(N, W);

    auto v = new int[](N);
    auto w = new int[](N);

    foreach(i ; 0 .. N){
        readVars(vi, wi);
        v[i] = vi;
        w[i] = wi;
    }

    auto memo = new int[][](N + 1, W + 1);

    foreach(i ; 0 .. N + 1){
        memo[i][] = -1;
    }

    int ans = memorec(N, v, w, memo, 0, W);

    writeln(ans);
}

int memorec(int N, int[] v, int[] w, int[][] memo, int i, int u){
    if (memo[i][u] != -1) {
        return memo[i][u];
    }
    else if (i == N || u == 0) {
        memo[i][u] = 0;
        return memo[i][u];
    }
    else {
        memo[i][u] = memorec(N, v, w, memo, i + 1, u);

        if (u - w[i] >= 0) {
            memo[i][u] = max(memo[i][u], memorec(N, v, w, memo, i + 1, u - w[i]) + v[i]);
        }

        return memo[i][u];
    }
}

void readVars(T...)(auto ref T args){
    auto line = readln.split;
    foreach(ref arg ; args){
        arg = line.front.to!(typeof(arg));
        line.popFront;
    }
    if(!line.empty){
        writeln(line);
        throw new Exception("args num < input num");
    }
}