#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#define fi first
#define se second
using namespace std;
short n,t;
typedef pair<short,short> td;
td a[3003];
int dp[3003],ans;
bool vis[3003];
int main(){
    scanf("%hd%hd",&n,&t);
    for (short i=1;i<=n;++i) scanf("%hd%hd",&a[i].fi,&a[i].se);
    sort(a+1,a+1+n);
    vis[0]=true;
    int tmp;
    for (short i=1;i<=n;++i)
    for (short j=t-1;j>=0;--j)
    if (vis[j]){
        tmp=dp[j]+a[i].se;
        ans=max(ans,tmp);
        if (j+a[i].fi<t) dp[j+a[i].fi]=max(dp[j+a[i].fi],tmp),vis[j+a[i].fi]=true;
    }
    printf("%d",ans);
}
