#include <bits/stdc++.h>

using namespace std;

const int N = 3e3 + 10;

int dp[N];
pair<int, int> dish[N];
int n, t;

int main() {
  cin.sync_with_stdio(false);
  cin.tie(0);

  cin >> n >> t;
  for (int i = 0; i < n; ++i) {
    cin >> dish[i].first >> dish[i].second;
  }

  sort(dish, dish+n);

  int ans = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < t; ++j) {
      ans = max(ans, dp[j] + dish[i].second);
    }
    for (int j = t-1; j >= dish[i].first; --j) {
      dp[j] = max(dp[j], dp[j-dish[i].first] + dish[i].second);
    }
  }

  cout << ans << endl;

  return 0;
}
