def main(): N,K = map(int, input().split()) L = [] for _ in range(N): p,d = map(int, input().split()) L.append((p, d)) L.sort(reverse=True) dp0 = [[0]*(K+1) for _ in range(N+1)] dp1 = [[0]*(K+1) for _ in range(N+1)] for i in range(N): for j in range(K+1): if j < L[i][0] and dp1[i][j] > 0: dp0[i+1][j] = max(dp0[i][j], dp1[i][j]+L[i][1]) elif j < L[i][0]: dp0[i+1][j] = dp0[i][j] else: if dp1[i][j] > 0: dp0[i+1][j] = max(dp0[i][j], dp1[i][j]+L[i][1]) else: dp0[i+1][j] = dp0[i][j] dp1[i+1][j] = max(dp1[i][j], dp0[i][j-L[i][0]]+L[i][1]) print(max(dp0[N][K], dp1[N][K])) if __name__ == "__main__": main()