N,I = map(int,input().split()) dp = [[-1<<60] * (I+1) for _ in range(N+1)] dp[0][0] = 0 for i in range(N): s,a = map(int,input().split()) for j in range(I+1): dp[i+1][j] = max(dp[i+1][j],dp[i][j]) if j + s <= I: dp[i+1][j+s] = max(dp[i+1][j+s],dp[i][j] + a) ans = 0 for j in range(I+1): ans = max(ans, dp[N][j]) print(ans)