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;

immutable long mod = 10^^9 + 7;
immutable int inf = mod;

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

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

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

    auto dp = new int[](W + 1);

    foreach(u ; 1 .. W + 1){
        foreach(i ; 0 .. N){
            if(u - w[i] >= 0){
                dp[u] = max(dp[u], dp[u - w[i]] + v[i]);
            }
        }
    }

    writeln(dp[W]);
}

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){
        throw new Exception("args num < input num");
    }
}