import sys readline = sys.stdin.readline N,I = map(int,readline().split()) ramen = [list(map(int,readline().split())) for i in range(N)] dp = [-1] * (I + 1) dp[0] = 0 for i in range(N): sio, aji = ramen[i] for j in range(I, -1, -1): if dp[j] == -1: continue if j + sio > I: continue if dp[j + sio] < dp[j] + aji: dp[j + sio] = dp[j] + aji print(max(dp))