N,I = map(int,input().split()) SA = [list(map(int,input().split())) for _ in range(N)] dp = [0] * (I+1) for s,a in SA: for i in reversed(range(I-s+1)): dp[i+s] = max(dp[i+s],dp[i] + a) print(dp[-1])