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)] for i in range(n - 1): d = A[i] - A[i + 1] for j in range(m + 1): dp[i + 2][j] = dp[i + 1][j] if j >= d: dp[i + 2][j] = max(dp[i + 2][j], dp[i][j - d] + A[i]) print(dp[-1][-1])