#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <cstring>
#include <map>

using namespace std;

typedef long long LL;
typedef vector<LL> VL;
typedef vector<vector<LL>> VVL;
typedef vector<string> VS;

#define REPD(i,a,b) for (LL i=(a);i<(b);i++)
#define REP(i,n) REPD(i,0,n)

LL llRead(){
  LL a;
  cin >> a;
  return a;
};

string stringRead(){
  string a;
  cin >> a;
  return a;
};

vector<LL> vlRead(LL a){
  vector<LL> rv;
  REP(i, a){
    LL input;
    cin >> input;
    rv.push_back(input);
  }
  return rv;
}

vector<string> vsRead(LL a){
  vector<string> rv;
  REP(i, a){
    string input;
    cin >> input;
    rv.push_back(input);
  }
  return rv;
}
vector<vector<LL>> vvlRead(LL a, LL b){
  vector<vector<LL>> rv;
  REP(i, a){
    rv.push_back(vector<LL>());
    REP(j, b) {
      LL input;
      cin >> input;
      rv.at(i).push_back(input);
    }
  }
  return rv;
}

#if 0
#define debug(d) debug1(__LINE__,#d, d)
void debug1(LL line, const char* name, VL& v) {
  cout << line << ":" << name << ":vector<LL>(" << v.size() << ") ";
  REP(i, (LL)v.size()) {
    cout << v.at(i) << " ";
  }
  cout << endl;
}
void debug1(LL line, const char* name, LL i) {
  cout << line << ":" << name << ":LL " << i << endl;;
}
void debug1(LL line, const char* name, VS& v) {
  cout << line << ":" << name << ":vector<string>(" << v.size() << ") ";
  REP(i, (LL)v.size()) {
    cout << v.at(i) << " ";
  }
  cout << endl;
}
void debug1(LL line, const char* name, VVL& v) {
  cout << line << ":" << name << ":vector<vector<LL>>(" << v.size() << ") ";
  REP(i, (LL)v.size()) {
    REP(j, (LL)v.at(i).size()) {
      cout << v.at(i).at(j) << " ";
    }
    cout << ", ";
  }
  cout << endl;
}
void debug1(LL line, const char* name, char* s) {
  cout << line << ":" << name << ":char* " << s << endl;;
}
void debug1(LL line, const char* name, vector<const char*>& v) {
  cout << line << ":" << name << ":vector<const char*>(" << v.size() << ") ";
  REP(i, (LL)v.size()) {
    cout << v.at(i) << " ";
  }
  cout << endl;
}
void debug1(LL line, const char* name, priority_queue<LL>& p) {
  cout << line << ":" << name << ":priority_queue<LL>(" << p.size() << ") ";
  priority_queue<LL> copy = p;
  while(!copy.empty()) {
    cout << copy.top() << " ";
    copy.pop();
  }
  cout << endl;
}
void debug1(LL line, const char* name, vector<pair<LL,LL>>& v) {
  cout << line << ":" << name << ":vector<pair<LL,LL>>(" << v.size() << ") ";
  REP(i, (LL)v.size()) {
    cout << v.at(i).first << "," << v.at(i).second << " ";
  }
  cout << endl;
}
void debug1(LL line, const char* name, map<LL,LL>& m) {
  cout << line << ":" << name << ":map<LL,LL>(" << m.size() << ") ";
  for (auto p : m) {
    cout << p.first << "," << p.second << " ";
  }
  cout << endl;
}
#else
#define debug(n)
#endif

int main(int argc, const char * argv[]) {
	cout.precision(16);
  // source code

  auto n = llRead();
  auto t = llRead();
  debug(n);
  debug(t);

  auto fmap = vvlRead(n, 2);  // [[time, score]]
  debug(fmap);
  sort(fmap.begin(), fmap.end(), [](vector<LL> a, vector<LL> b){ return a[0] < b[0];});
  debug(fmap);

  vector<LL> prev(t);  // [time, score]
  vector<LL> cur(t);  // [time, score]

  LL m = 0;
  REP(i, n) {
    debug(prev);
    REP(time, t) {
      LL score = prev[time];
      cur[time] = max(cur[time], score);
      auto ntime = time + fmap[i][0];
      if (ntime < t) {
        cur[ntime] = max(cur[ntime], score + fmap[i][1]);
      }
      m = max(m, score+fmap[i][1]);
    }
    swap(prev, cur);
    REP(time, t) {
      cur[time] = 0;
    }
  }
  debug(prev);

  cout << m << endl;



  return 0;
}


Measured memory_bytes: 512