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 dp = new int[](W + 1);

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

    int ans = dp[W];

    writeln(ans);
}

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");
    }
}