#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
using ld = long double;
using mint = modint998244353;

int N, I, s[1010], a[1010];
int dp[1010][1010];

int main() {
  cin >> N >> I;
  for (int i = 0; i < N; i++) cin >> s[i] >> a[i];
  for (int i = 0; i < N; i++) {
    for (int j = 0; j <= I; j++) {
      dp[i + 1][j] = dp[i][j];
      if (j - s[i] >= 0) dp[i + 1][j] = max(dp[i + 1][j], dp[i][j - s[i]] + a[i]);
    }
  }
  int ans = 0;
  for (int j = 0; j <= I; j++) ans = max(ans, dp[N][j]);
  cout << ans << endl;
  return 0;
}