N, P = map(int, input().split()) A = list(map(int, input().split())) A.sort() # dp[i,j]: i番目の要素を取る、不平等さj -> Oの最大値 #隣り合う2つをO, Eとするのがベスト dp = [[0] * (P + 1) for _ in range(N + 2)] for i in range(1, N): get = A[i] pena = A[i] - A[i-1] for j in range(P+1): dp[i][j] = max(dp[i][j], dp[i-1][j]) for j in reversed(range(pena, P+1)): dp[i+1][j] = max(dp[i+1][j], dp[i-1][j-pena] + get) for i in range(P+1): dp[N][i] = max(dp[N][i], dp[N-1][i]) print(max(dp[N]))