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