import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy



sys.setrecursionlimit(10**7)

inf=10**20

mod=10**9+7

dd=[(-1,0),(0,1),(1,0),(0,-1)]

ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]



def LI(): return [int(x) for x in sys.stdin.readline().split()]

def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]

def I(): return int(sys.stdin.readline())

def LS(): return sys.stdin.readline().split()

def S(): return eval(input())



def main():

  n,k=LI()

  l=LI()



  ans=-inf

  a=min(n,k)

  for i in range(a+1):

    sm=0

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

      if j!=0:

        _q=l[:i]+l[-j:]

      else:

        _q=l[:i]



      q=[]

      for x in _q:

        heapq.heappush(q,x)

      ans=max(ans,sum(q))



      for _ in range(k-i-j):

        if len(q)>0:

          heapq.heappop(q)

          ans=max(ans,sum(q))

        else:

          break



  return ans



# main()

print((main()))

import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy



sys.setrecursionlimit(10**7)

inf=10**20

mod=1000000007

dd=[(-1,0),(0,1),(1,0),(0,-1)]

ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]



def LI(): return [int(x) for x in sys.stdin.readline().split()]

def I(): return int(sys.stdin.readline())

def LS(): return sys.stdin.readline().split()

def S(): return eval(input())



def main():

  n,k=LI()

  l=LI()



  cnt=min(n,k)

  ans=0

  for i in range(cnt+1):

    for j in range(cnt-i+1):

      q=[]

      for _i in range(i):

        heapq.heappush(q,l[_i])



      for _j in range(j):

        heapq.heappush(q,l[-(_j+1)])



      ln=len(q)

      for _ in range(min(k-i-j,ln)):

        x=heapq.heappop(q)

        if x>0:

          q.append(x)

          break

      # print(q)

      ans=max(ans,sum(q))



  return ans



# main()

print((main()))

import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, queue, copy

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]


def LI():
    return [int(x) for x in sys.stdin.readline().split()]


def LI_():
    return [int(x) - 1 for x in sys.stdin.readline().split()]


def I():
    return int(sys.stdin.readline())


def LS():
    return sys.stdin.readline().split()


def S():
    return eval(input())


def main():
    n, k = LI()
    l = LI()
    ans = -inf
    a = min(n, k)
    for i in range(a + 1):
        sm = 0
        for j in range(a + 1 - i):
            if j != 0:
                _q = l[:i] + l[-j:]
            else:
                _q = l[:i]
            q = []
            for x in _q:
                heapq.heappush(q, x)
            ans = max(ans, sum(q))
            for _ in range(k - i - j):
                if len(q) > 0:
                    heapq.heappop(q)
                    ans = max(ans, sum(q))
                else:
                    break
    return ans


# main()
print((main()))

import math, itertools, fractions, heapq, collections, bisect, sys, queue, copy

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 1000000007
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]


def LI():
    return [int(x) for x in sys.stdin.readline().split()]


def I():
    return int(sys.stdin.readline())


def LS():
    return sys.stdin.readline().split()


def S():
    return eval(input())


def main():
    n, k = LI()
    l = LI()
    cnt = min(n, k)
    ans = 0
    for i in range(cnt + 1):
        for j in range(cnt - i + 1):
            q = []
            for _i in range(i):
                heapq.heappush(q, l[_i])
            for _j in range(j):
                heapq.heappush(q, l[-(_j + 1)])
            ln = len(q)
            for _ in range(min(k - i - j, ln)):
                x = heapq.heappop(q)
                if x > 0:
                    q.append(x)
                    break
            # print(q)
            ans = max(ans, sum(q))
    return ans


# main()
print((main()))

-import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, queue, copy +import math, itertools, fractions, heapq, collections, bisect, sys, queue, copy -mod = 10**9 + 7 +mod = 1000000007 - - -def LI_(): -    return [int(x) - 1 for x in sys.stdin.readline().split()] -    ans = -inf -    a = min(n, k) -    for i in range(a + 1): -        sm = 0 -        for j in range(a + 1 - i): -            if j != 0: -                _q = l[:i] + l[-j:] -            else: -                _q = l[:i] +    cnt = min(n, k) +    ans = 0 +    for i in range(cnt + 1): +        for j in range(cnt - i + 1): -            for x in _q: -                heapq.heappush(q, x) +            for _i in range(i): +                heapq.heappush(q, l[_i]) +            for _j in range(j): +                heapq.heappush(q, l[-(_j + 1)]) +            ln = len(q) +            for _ in range(min(k - i - j, ln)): +                x = heapq.heappop(q) +                if x > 0: +                    q.append(x) +                    break +            # print(q) -            for _ in range(k - i - j): -                if len(q) > 0: -                    heapq.heappop(q) -                    ans = max(ans, sum(q)) -                else: -                    break