#include<bits/stdc++.h>
using namespace std;

long long dp[2][3003];

int main()
{

        long long n,m,a,b,c,d,e,f,g,h,p,q,r,fr,sc,tr,sz,tz,i,j,k,mx=LLONG_MIN,mn=LLONG_MAX;
        long long x=0,y=0,cnt=0,res=0,ttl=0,ans=0,sum=0; long long flg=0,flag=1,na=0,as=1;
        vector<long long>u,v,w; vector< pair<long long,long long> >vct; vector<string>vst;
        set<long long>st,nt,tt; map<long long,long long>mp,nq,qr; string str,ttr,ntr;

        scanf("%lld %lld",&n,&k);

        for(i=1;i<=n;i++)
        {
            scanf("%lld %lld",&a,&b); vct.push_back(make_pair(a,b));
        }


        sort(vct.begin(),vct.end());

        long long idx,cap;

        for(idx=n-1;idx>=0;idx--)
        {
            for(cap=1;cap<=k;cap++)
            {
                fr=idx%2; sc=(idx+1)%2; a=vct[idx].first; b=vct[idx].second;

                p=0; q=0;

                if(idx==n-1 || cap-a<=0){  p=b; }
                else{  p=b+dp[sc][cap-a];   }

                if(idx!=n-1){  q=dp[sc][cap];  }

                dp[fr][cap]=max(p,q);


            }
        }

        printf("%lld\n",dp[0][k]);








    return 0;
}




#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define REP(i,n) for(int _n=n, i=0;i<_n;++i)
#define FOR(i,a,b) for(int i=(a),_b=(b);i<=_b;++i)
#define FORD(i,a,b) for(int i=(a),_b=(b);i>=_b;--i)
using ull = uint64_t;
using ll = int64_t;
using PII = pair<int, int>;
using VI = vector<int>;

string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string) s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B> string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
template <typename A> string to_string(A v) {
bool first = true; string res = "{";
for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); }
res += "}"; return res; }
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H); debug_out(T...); }
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

const int N = 3005;
int n, t;
int A[N], B[N];
int dp[N][N][2];

int rec(int idx, int left, int last) {
    if (idx == n) {
        return 0;
    }
    if (left <= 0) {
        return 0;
    }
    if (dp[idx][left][last] != -1) return dp[idx][left][last];
    if (last == 1) {
        if (A[idx] <= left) {
            dp[idx][left][last] = max(rec(idx + 1, left - A[idx], 1) + B[idx], rec(idx + 1, left, 1));
        } else {
            dp[idx][left][last] = rec(idx + 1, left, 1);
        }
    } else {
        if (A[idx] <= left) {
            dp[idx][left][last] = max({rec(idx + 1, left - A[idx], 0) + B[idx], rec(idx + 1, left, 0), rec(idx + 1, left - 1, 1) + B[idx]});
        } else {
            dp[idx][left][last] = max(rec(idx + 1, left - 1, 1) + B[idx], rec(idx + 1, left, 0));
        }
    }
    return dp[idx][left][last];
}



int main() {
    ios::sync_with_stdio(false), cin.tie(0);
    cin >> n >> t;
    REP(i, n) {
        cin >> A[i];
        cin >> B[i];
    }
    memset(dp, -1, sizeof dp);
    cout << rec(0, t, 0) << "\n";
}