### BUGGY CODE ###

#coding:utf-8
def dbg(*something):
    if DEBUG:
        print(*something)






#正の宝石を戻すことはない
#負の宝石を戻すのは後半

from math import ceil,floor
DEBUG = False
N,K = list(map(int,input().split()))
V = list(map(int,input().split()))


#残りk回のとき深さk以下の場所に正の宝石がない→終了
#i回の操作で取れる石>それまでにとるi-1個の石の和
#深さiにある石vの価値：v - (それまでにとるi-1個の石の和　except (k-i)個の負の石)
'''
'''




def tansaku(V,rK,N,score):
    dbg(V,rK,N,score)
    # if rK == 0:
    #     db[]
    #     return score + sum(N)


    max_v = score + sum(sorted(N)[rK:])
    LV = V[:ceil(len(V)/2)]
    RV = V[floor(len(V)/2):][::-1]



    n = []
    for i in range(min(rK,len(LV))):
        
        if LV[i] <= 0:
            n.append(LV[i])
            continue
        # tmpL = LV[:i]
        # tmpL.sort()
        # j = 0 #捨てる石の数
        # for _ in range(min(rK - 1 - i,len(tmpL)) ):
        #     if tmpL[j] >= 0:
        #         break
        #     j += 1
        # dbg("dbg= ",tmpL)
        # v_tmp = sum(tmpL[j:]) + LV[i]

        # if v_tmp > 0:
        #     next_V = V[i+1:]
        #     next_rK = rK - 1 - i - j
        #     max_v = max(tansaku(next_V,next_rK) + v_tmp, max_v)
        next_V = V[i+1:]
        next_rK = rK - 1 - i
        next_tmp_v = tansaku(next_V, next_rK, N+n, score+LV[i])
        max_v = max(next_tmp_v , max_v)


        break

    n = []
    for i in range(min(rK,len(RV))):
        
        if RV[i] <= 0:
            n.append(RV[i])
            continue
        # tmpL = RV[:i]
        # tmpL.sort()
        # j = 0 #捨てる石の数
        # for _ in range(min(rK - 1 - i,len(tmpL)) ):
        #     if tmpL[j] >= 0:
        #         break
        #     j += 1
        # dbg("dbg= ",tmpL)
        # v_tmp = sum(tmpL[j:]) + RV[i]

        # if v_tmp > 0:
        #     next_V = V[::-1][i+1:]
        #     next_rK = rK - 1 - i - j
        #     max_v = max(tansaku(next_V,next_rK) + v_tmp,max_v)
            # break
        next_V = V[::-1][i+1:][::-1]
        next_rK = rK - 1 - i
        next_tmp_v = tansaku(next_V,next_rK,N+n,score+RV[i])
        max_v = max(next_tmp_v , max_v)
        break


    return max_v

print(tansaku(V,K,[],0))

    






### FIXED CODE ###

#coding:utf-8



def main():
    
    def dbg(*something):
        if DEBUG:
            print(*something)


    #正の宝石を戻すことはない
    #負の宝石を戻すのは後半
    from sys import stdin
    from math import ceil,floor
    DEBUG = False
    N,K = list(map(int,stdin.readline().split()))
    V = list(map(int,stdin.readline().split()))
    
    max_value = 0
    dbg([i for i in range(3,-1,-1)])
    for getnum in range(1,min(N+1,K+1)):  #取る宝石の総数
        for a in range(getnum + 1):  #左から石を取る回数
            J = [0] * getnum #石
            b = getnum - a #右から石を取る回数
            for i in range(a):
                J[i] = V[i]
            for i in range(b):
                J[a+i] = V[-i-1]
            J.sort()
            #dbg(J,a,b)
            t = min(K-getnum,getnum) #捨てる石
           
            for i in range(t): 
                if J[i] >= 0:
                    t = i
                    break
            #dbg(J,i,t,a,b,J[t:])
            tmp_max = sum(J[t:])

            max_value = max(max_value,tmp_max)
    print(max_value)



if __name__ == '__main__':
    main()