N,W=map(int,input().split()) inf=1<<60 dp=[-inf]*(W+1) dp[0]=0 for n in range(N): w,v=map(int,input().split()) for s in range(W,w-1,-1): dp[s]=max(dp[s],dp[s-w]+v) for w in range(1,W+1): dp[w]=max(dp[w],dp[w-1]) for X in range(1,W+1): ans=dp[W]-dp[W-X]+1 print(ans)