# -*- coding: utf-8 -*-

"""

Created on Sun May 26 20:56:05 2019



@author: Yamazaki Kenichi

"""

import heapq



N,K = list(map(int,input().split()))

V = list(map(int,input().split()))



def a(K):

    if K > N:

        return N

    else:

        return K



ans = 0

for i in range(K):

    for j in range(a(K-i)+1):

        tmp = 0

        minus = [0]

        for k in range(a(K-i)):

            tmp += V[k-j]

            heapq.heappush(minus,V[k-j])

#            print(tmp,minus)

        for k2 in range(i):

            if minus[0] < 0:

                tmp += (-heapq.heappop(minus))

            else:

                break

#        print(ans,tmp,i,j,k)

        ans = max(ans,tmp)

    

print(ans)
# -*- coding: utf-8 -*-

"""

Created on Wed May 29 22:59:58 2019



@author: Yamazaki Kenichi

"""



N, K = list(map(int,input().split()))

V = list(map(int,input().split()))



ans = 0

for pickup_n in range(min(K, N)+1):

    for start in range(pickup_n + 1):

        tmp = [0]

        for i in range(pickup_n):

            tmp.append(V[i - start])

        tmp.sort()

        for i in range(K - pickup_n):

            if tmp[i] < 0:

                tmp[i] = 0

            else:

                break

        ans = max(ans,sum(tmp))

print(ans)



# -*- coding: utf-8 -*-
"""
Created on Sun May 26 20:56:05 2019
@author: Yamazaki Kenichi
"""
import heapq

N, K = list(map(int, input().split()))
V = list(map(int, input().split()))


def a(K):
    if K > N:
        return N
    else:
        return K


ans = 0
for i in range(K):
    for j in range(a(K - i) + 1):
        tmp = 0
        minus = [0]
        for k in range(a(K - i)):
            tmp += V[k - j]
            heapq.heappush(minus, V[k - j])
        #            print(tmp,minus)
        for k2 in range(i):
            if minus[0] < 0:
                tmp += -heapq.heappop(minus)
            else:
                break
        #        print(ans,tmp,i,j,k)
        ans = max(ans, tmp)
print(ans)

# -*- coding: utf-8 -*-
"""
Created on Wed May 29 22:59:58 2019
@author: Yamazaki Kenichi
"""
N, K = list(map(int, input().split()))
V = list(map(int, input().split()))
ans = 0
for pickup_n in range(min(K, N) + 1):
    for start in range(pickup_n + 1):
        tmp = [0]
        for i in range(pickup_n):
            tmp.append(V[i - start])
        tmp.sort()
        for i in range(K - pickup_n):
            if tmp[i] < 0:
                tmp[i] = 0
            else:
                break
        ans = max(ans, sum(tmp))
print(ans)

-Created on Sun May 26 20:56:05 2019 +Created on Wed May 29 22:59:58 2019 -import heapq - - - -def a(K): -    if K > N: -        return N -    else: -        return K - - -for i in range(K): -    for j in range(a(K - i) + 1): -        tmp = 0 -        minus = [0] -        for k in range(a(K - i)): -            tmp += V[k - j] -            heapq.heappush(minus, V[k - j]) -        #            print(tmp,minus) -        for k2 in range(i): -            if minus[0] < 0: -                tmp += -heapq.heappop(minus) +for pickup_n in range(min(K, N) + 1): +    for start in range(pickup_n + 1): +        tmp = [0] +        for i in range(pickup_n): +            tmp.append(V[i - start]) +        tmp.sort() +        for i in range(K - pickup_n): +            if tmp[i] < 0: +                tmp[i] = 0 -        #        print(ans,tmp,i,j,k) -        ans = max(ans, tmp) +        ans = max(ans, sum(tmp))