n,w = map(int,input().split()) wv = [list(map(int,input().split())) for i in range(n)] INF = 10**15 dp = [-INF]*(w+1) dp[0] = 0 for i in range(1,n+1): new = [-INF]*(w+1) wi,vi = wv[i-1] for j in range(w+1): new[j] = dp[j] if j >= wi: new[j] = max(new[j], dp[j-wi] + vi) dp = new pre = dp[::1] for i in range(1,w+1): pre[i] = max(pre[i-1], pre[i]) mx = max(dp) for x in range(1,w+1): ans = mx - pre[w-x] + 1 print(ans)