import sys 
input = sys.stdin.buffer.readline
def main():
    N,M = map(int,input().split()); INF = float("inf")
    A = list(map(int,input().split()))
    A.sort(reverse=True)

    dp = [[INF]*(N+1) for _ in range(N+1)]
    dp[0][0] = 0
    for i in range(1,N+1):
        for j in range(1,N+1):
            if j%2 == 1: #奇数個
                dp[i][j] = min(dp[i-1][j], dp[i-1][j-1] + A[i-1])
            else:
                dp[i][j] = min(dp[i-1][j], dp[i-1][j-1] - A[i-1])
    #print(dp)

    ans = 0
    for i in reversed(range(N+1)):
        if i%2 == 0 and dp[N][i] <= M:
            dif = dp[N][i]
            num = i
            break
    #print(dif,num)
    #最後の和と個数(=2k)
    now = N
    while now > 0:
        #now番目を選ばない
        for i in range(now+1):
            if dp[i][num] == dif:
                if num%2 == 0:
                    num -= 1
                    dif += A[i-1]
                else:
                    ans += A[i-1]
                    num -= 1
                    dif -= A[i-1]
                now = i
                break
    print(ans)
        
if __name__ == '__main__':
    main()