#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
int main() {
  int N, T;
  int res = 0;
  cin >> N >> T;
  vector<vector<int>> A(N, vector<int> (2));
  for (int i = 0; i < N; i++) {
    cin >> A[i][0] >> A[i][1];
  }
  sort(A.begin(), A.end());
  vector<int> dp(T, 0);
  for (int i = 0; i < N; i++) {
    vector<int> new_dp = dp;
    for (int j = 0; j <= T - 1; j++) {
      res = max(res, dp[j] + A[i][1]);
      if (j + A[i][0] <= T - 1) {
        new_dp[j + A[i][0]] = max(dp[j] + A[i][1], new_dp[j + A[i][0]]);
      }
    }
    swap(dp, new_dp);
  }
  cout << res << endl;
  return 0;
}