import sys



read = sys.stdin.buffer.read

input = sys.stdin.buffer.readline

inputs = sys.stdin.buffer.readlines





# rstrip().decode('utf-8')

# INF=float("inf")

#MOD=10**9+7

# sys.setrecursionlimit(2147483647)

# import math

#import numpy as np

# import operator

# import bisect

# from heapq import heapify,heappop,heappush

#from math import gcd

# from fractions import gcd

# from collections import deque

# from collections import defaultdict

# from collections import Counter

from itertools import accumulate

# from itertools import groupby

# from itertools import permutations

# from itertools import combinations

# from scipy.sparse import csr_matrix

# from scipy.sparse.csgraph import floyd_warshall

# from scipy.sparse.csgraph import csgraph_from_dense

# from scipy.sparse.csgraph import dijkstra

# map(int,input().split())





def main():

	n,k=list(map(int,input().split()))

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

	V=[0]+V+[0]

	LL=list(accumulate(V))

	RR=list(accumulate(V[::-1]))[::-1]

	ans=0

	for l in range(n+1):

		for r in range(n-l+1):

			for x in range(l+r+1):

				if l+r+x<=k:

					xx=V[1:l+1]+V[n+1-r:n+1]

					xx.sort()

					xxx=list(accumulate(xx))

					xxx=[0]+xxx

					ans=max(ans,LL[l]+RR[n-r+1]-xxx[x])

	print(ans)



if __name__ == "__main__":

		main()

import sys

input = sys.stdin.buffer.readline



#sys.setrecursionlimit(10**9)

#from functools import lru_cache



def RD(): return input().rstrip().decode()

def II(): return int(eval(input()))

def FI(): return int(eval(input()))

def MI(): return list(map(int,input().split()))

def MF(): return list(map(float,input().split()))

def LI(): return list(map(int,input().split()))

def LF(): return list(map(float,input().split()))

def TI(): return tuple(map(int,input().split()))

# rstrip().decode()





def main():

	n,k=MI()

	V=LI()



	ans=0



	for a in range(min(n+1,k+1)):

		for b in range(min(n-a+1,k-a+1)):

			S=[]

			S+=V[:a]

			S+=V[n-b:]

			S.sort()

			tmp=sum(S)

			cnt=max(0,k-a-b)

			for i in range(min(a+b,cnt)):



				if S[i]<0:

					tmp-=S[i]

				else:

					break

			ans=max(ans,tmp)

	print(ans)





















if __name__ == "__main__":

	main()

import sys

read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs = sys.stdin.buffer.readlines
# rstrip().decode('utf-8')
# INF=float("inf")
# MOD=10**9+7
# sys.setrecursionlimit(2147483647)
# import math
# import numpy as np
# import operator
# import bisect
# from heapq import heapify,heappop,heappush
# from math import gcd
# from fractions import gcd
# from collections import deque
# from collections import defaultdict
# from collections import Counter
from itertools import accumulate

# from itertools import groupby
# from itertools import permutations
# from itertools import combinations
# from scipy.sparse import csr_matrix
# from scipy.sparse.csgraph import floyd_warshall
# from scipy.sparse.csgraph import csgraph_from_dense
# from scipy.sparse.csgraph import dijkstra
# map(int,input().split())
def main():
    n, k = list(map(int, input().split()))
    V = list(map(int, input().split()))
    V = [0] + V + [0]
    LL = list(accumulate(V))
    RR = list(accumulate(V[::-1]))[::-1]
    ans = 0
    for l in range(n + 1):
        for r in range(n - l + 1):
            for x in range(l + r + 1):
                if l + r + x <= k:
                    xx = V[1 : l + 1] + V[n + 1 - r : n + 1]
                    xx.sort()
                    xxx = list(accumulate(xx))
                    xxx = [0] + xxx
                    ans = max(ans, LL[l] + RR[n - r + 1] - xxx[x])
    print(ans)


if __name__ == "__main__":
    main()

import sys

input = sys.stdin.buffer.readline
# sys.setrecursionlimit(10**9)
# from functools import lru_cache
def RD():
    return input().rstrip().decode()


def II():
    return int(eval(input()))


def FI():
    return int(eval(input()))


def MI():
    return list(map(int, input().split()))


def MF():
    return list(map(float, input().split()))


def LI():
    return list(map(int, input().split()))


def LF():
    return list(map(float, input().split()))


def TI():
    return tuple(map(int, input().split()))


# rstrip().decode()
def main():
    n, k = MI()
    V = LI()
    ans = 0
    for a in range(min(n + 1, k + 1)):
        for b in range(min(n - a + 1, k - a + 1)):
            S = []
            S += V[:a]
            S += V[n - b :]
            S.sort()
            tmp = sum(S)
            cnt = max(0, k - a - b)
            for i in range(min(a + b, cnt)):
                if S[i] < 0:
                    tmp -= S[i]
                else:
                    break
            ans = max(ans, tmp)
    print(ans)


if __name__ == "__main__":
    main()

-read = sys.stdin.buffer.read -inputs = sys.stdin.buffer.readlines -# rstrip().decode('utf-8') -# INF=float("inf") -# MOD=10**9+7 -# sys.setrecursionlimit(2147483647) -# import math -# import numpy as np -# import operator -# import bisect -# from heapq import heapify,heappop,heappush -# from math import gcd -# from fractions import gcd -# from collections import deque -# from collections import defaultdict -# from collections import Counter -from itertools import accumulate +# sys.setrecursionlimit(10**9) +# from functools import lru_cache +def RD(): +    return input().rstrip().decode() -# from itertools import groupby -# from itertools import permutations -# from itertools import combinations -# from scipy.sparse import csr_matrix -# from scipy.sparse.csgraph import floyd_warshall -# from scipy.sparse.csgraph import csgraph_from_dense -# from scipy.sparse.csgraph import dijkstra -# map(int,input().split()) + +def II(): +    return int(eval(input())) + + +def FI(): +    return int(eval(input())) + + +def MI(): +    return list(map(int, input().split())) + + +def MF(): +    return list(map(float, input().split())) + + +def LI(): +    return list(map(int, input().split())) + + +def LF(): +    return list(map(float, input().split())) + + +def TI(): +    return tuple(map(int, input().split())) + + +# rstrip().decode() -    n, k = list(map(int, input().split())) -    V = list(map(int, input().split())) -    V = [0] + V + [0] -    LL = list(accumulate(V)) -    RR = list(accumulate(V[::-1]))[::-1] +    n, k = MI() +    V = LI() -    for l in range(n + 1): -        for r in range(n - l + 1): -            for x in range(l + r + 1): -                if l + r + x <= k: -                    xx = V[1 : l + 1] + V[n + 1 - r : n + 1] -                    xx.sort() -                    xxx = list(accumulate(xx)) -                    xxx = [0] + xxx -                    ans = max(ans, LL[l] + RR[n - r + 1] - xxx[x]) +    for a in range(min(n + 1, k + 1)): +        for b in range(min(n - a + 1, k - a + 1)): +            S = [] +            S += V[:a] +            S += V[n - b :] +            S.sort() +            tmp = sum(S) +            cnt = max(0, k - a - b) +            for i in range(min(a + b, cnt)): +                if S[i] < 0: +                    tmp -= S[i] +                else: +                    break +            ans = max(ans, tmp)