n, i = map(int, input().split()) DP = [[-1 for _ in range(i + 1)] for _ in range(n + 1)] DP[0][0] = 0 for j in range(n): s, a = map(int, input().split()) for x in range(i + 1): if DP[j][x] != -1: DP[j + 1][x] = max(DP[j + 1][x], DP[j][x]) if x + s <= i: DP[j + 1][x + s] = max(DP[j + 1][x + s], DP[j][x] + a) print(max(DP[n]))