N, M = map(int, input().split()) A = list(map(int, input().split())) A.sort(reverse=True) dp0 = [[0] * (M + 1) for i in range(N + 1)] dp1 = [[0] * (M + 1) for i in range(N + 1)] for i in range(1, N): for m in range(M + 1): dp0[i][m] = max(dp0[i - 1][m], dp1[i - 1][m]) if i >= 1: d = A[i - 1] - A[i] if m - d >= 0: dp1[i][m] = max(dp1[i][m], dp0[i - 1][m - d] + A[i - 1]) if i >= 2: d = A[i - 2] - A[i] if m - d >= 0: dp1[i][m] = max(dp1[i][m], dp0[i - 2][m - d] + A[i - 2]) ans = 0 for i in range(N + 1): for m in range(M + 1): ans = max(ans, dp0[i][m], dp1[i][m]) print(ans)