// Slower C++ solution:
#include <iostream>

#include <algorithm>

#include <map>

#include <queue>

#include <set>

#include <stack>

#include <string>

#include <string.h>

#include <vector>

#include <queue>

#include <cmath>

#include <bitset>

#include <complex>

#include <functional>

#include <numeric>

#include <iomanip>



// output

#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');

#define YES cout << "YES" << endl

#define Yes cout << "Yes" << endl

#define NO cout << "NO" << endl

#define No cout << "No" << endl

// utility

#define ALL(i) (i).begin(), (i).end()

#define FOR(i, a, n) for(int i=(a);i<(n);++i)

#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)

#define REP(i, n) for(int i=0;i<int(n);++i)

#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)

#define IN(a, x, b) (a<=x && x<b)

#define OUT(a, x, b) (x<a || b<=x)

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }



// type/const

#define int ll

using ll = long long;

using ull = unsigned long long;

using ld = long double;

const int MOD = 1000000007;

/* const int MOD = 998244353; */

const int INF = 1e18;

const double PI = acos(-1);



using namespace std;

struct INIT { INIT(){

  cin.tie(0); ios::sync_with_stdio(false);

  cout << fixed << setprecision(10);

}}INIT;





signed main() {

  int N, T; 

  cin >> N >> T;



  vector<int> A(N), B(N);

  REP(i, N) cin >> A[i] >> B[i];



  vector<int> o(N);

  iota(ALL(o), 0);

  sort(ALL(o), [&](int const & l, int const & r){

      return A[l] < A[r];

      });



  vector<vector<int>> dp(N+1, vector<int>(6010, -INF));

  dp[0][0] = 0;



  REP(i, N) REP(j, T){

    int I = o[i];

    chmax(dp[i+1][j], dp[i][j]);

    chmax(dp[i+1][j+A[I]], dp[i][j]+B[I]);

  }



  int ans = 0;

  REP(i, N+1) REP(j, 6010){

    chmax(ans, dp[i][j]);

  }



  cout << ans << "\n";



  return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.822841459926763x):
#include <iostream>

#include <algorithm>

#include <map>

#include <queue>

#include <set>

#include <stack>

#include <string>

#include <string.h>

#include <vector>

#include <queue>

#include <cmath>

#include <bitset>

#include <complex>

#include <functional>

#include <numeric>

#include <iomanip>



// output

#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');

#define YES cout << "YES" << endl

#define Yes cout << "Yes" << endl

#define NO cout << "NO" << endl

#define No cout << "No" << endl

// utility

#define ALL(i) (i).begin(), (i).end()

#define FOR(i, a, n) for(int i=(a);i<(n);++i)

#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)

#define REP(i, n) for(int i=0;i<int(n);++i)

#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)

#define IN(a, x, b) (a<=x && x<b)

#define OUT(a, x, b) (x<a || b<=x)

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }



// type/const

#define int ll

using ll = long long;

using ull = unsigned long long;

using ld = long double;

const int MOD = 1000000007;

/* const int MOD = 998244353; */

const int INF = 1e18;

const double PI = acos(-1);



using namespace std;

struct INIT { INIT(){

  cin.tie(0); ios::sync_with_stdio(false);

  cout << fixed << setprecision(10);

}}INIT;





signed main() {

  int N, T; 

  cin >> N >> T;



  vector<int> A(N), B(N);

  REP(i, N) cin >> A[i] >> B[i];



  vector<int> o(N);

  iota(ALL(o), 0);

  sort(ALL(o), [&](int const & l, int const & r){

      return A[l] < A[r];

      });



  vector<vector<int>> dp(N+1, vector<int>(T+1, -INF));

  dp[0][0] = 0;



  REP(i, N) REP(j, T+1){

    int I = o[i];

    chmax(dp[i+1][j], dp[i][j]);

    if(j < T) chmax(dp[i+1][min(T, j+A[I])], dp[i][j]+B[I]);

  }



  int ans = 0;

  REP(j, T+1) chmax(ans, dp[N][j]);



  cout << ans << "\n";



  return 0;

}