from tkinter import RIDGE n, mx = map(int, input().split()) dp = [0] * (mx + 1) for _ in range(n): s, a = map(int, input().split()) for i in range(mx - s + 1)[::-1]: dp[i + s] = max(dp[i + s], dp[i] + a) print(dp[mx])