N,M = map(int,input().split()) A = list(map(int,input().split())) A.sort(reverse = True) import sys if N == 2: d = A[0] - A[1] if d <= M: print(A[0]) else: print(0) exit() inf = 10 ** 10 dp = [[0] * (M+1) for _ in range(N-1)] if A[0] - A[1] <= M: dp[0][A[0]-A[1]] = A[0] if A[1] - A[2] <= M: dp[1][A[1]-A[2]] = A[1] for i in range(1,N-1): d = A[i] - A[i+1] for j in range(M+1): dp[i][j] = dp[i-1][j] if i == 1:continue for j in range(M+1): if j + d <= M: dp[i][j+d] = max(dp[i][j+d],dp[i-2][j] + A[i]) else: break _max = 0 for j in range(M+1): if dp[-1][j] > _max: _max = dp[-1][j] if dp[-2][j] > _max: _max = dp[-2][j] print(_max)