void main() {
    int[] tmp = readln.split.to!(int[]);
    int n = tmp[0], t = tmp[1];
    int[] a = new int[n], b = new int[n];
    foreach (i; 0 .. n) {
        tmp = readln.split.to!(int[]);
        a[i] = tmp[0], b[i] = tmp[1];
    }
    zip(b, a).sort!((t1, t2) => t1[0] > t2[0]);
    int time, happiness, i;
    while (i < n) {
        if (time + a[i] < t) {
            time += a[i];
            happiness += b[i];
            a = a.remove(i);
            b = b.remove(i);
            --n;
        } else {
            ++i;
        }
    }
    if (!b.empty) happiness += b.reduce!max;
    happiness.writeln;
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;