INF = 10 ** 18 #入力 n, m = map(int, input().split()) a = list(map(int, input().split())) a.sort(reverse=True) #配列の初期化 dp = [[0] * (m + 1) for _ in range(n + 1)] #dp配列 w = [a[i] - a[i + 1] for i in range(n - 1)] #重さ v = [a[i] for i in range(n - 1)] #価値 #ナップサックdpの計算 for i in range(n): for j in range(m + 1): if i < n - 1 and j + w[i] <= m: dp[i + 2][j + w[i]] = dp[i][j] + v[i] dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]) ans = max(dp[n]) print(ans)