import sys input = sys.stdin.readline from collections import * 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(1, N+1): for j in range(M+1): dp[i][j] = max(dp[i][j], dp[i-1][j]) if i>=2: for j in range(M+1): k = j+A[i-2]-A[i-1] if k<=M: dp[i][k] = max(dp[i][k], dp[i-2][j]+A[i-2]) print(max(dp[N]))