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

immutable long MOD = 10^^9 + 7;

void main() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto M = s[1];
    auto W = new int[](N);
    auto V = new long[](N);
    foreach (i; 0..N) {
        s = readln.split.map!(to!int);
        W[i] = s[0];
        V[i] = s[1];
    }

    auto dp = new long[][](N+1, M+1);

    foreach (i; 0..N) {
        dp[i+1] = dp[i].dup;
        foreach (j; 0..M+1) {
            if (j + W[i] > M) break;
            dp[i+1][j+W[i]] = max(dp[i+1][j+W[i]], dp[i][j] + V[i]);
        }
    }

    dp[N].reduce!max.writeln;
}
