n,I = map(int,input().split()) inf = 10**2 dp = [-inf] * (I+1) dp[0] = 0 for i in range(n): n_dp = [-inf] * (I+1) s,a = map(int,input().split()) for j in range(I+1): n_dp[j] = max(n_dp[j],dp[j]) if j + s <= I: n_dp[j+s] = max(n_dp[j+s],dp[j] + a) dp = n_dp import sys print(max(dp))