def solve():
  ans = 0
  N, K = map(int, input().split())
  V = list(map(int, input().split()))
  A = V[:]*2
  for k in range(K,-1,-1): #kは操作回数
    if k>=N:
      suteru = k-N
      a = V[:]
      a.sort()
      ans = max(ans,sum(a[suteru:]))
    else:
      for i in range(k//2+1,k+1): #iは取る回数
        suteru = k-i
        for j in range(i+1):
          a = A[N-j:N+i-j]
          a.sort()
          ans = max(ans,sum(a[suteru:]))
  return ans
print(solve()) def solve():
  ans = 0
  N, K = map(int, input().split())
  V = list(map(int, input().split()))
  A = V[:]*2
  for k in range(K,-1,-1): #kは操作回数
    if k>=N:
      suteru = k-N
      a = V[:]
      a.sort()
      ans = max(ans,sum(a[suteru:]))
    else:
      for i in range(k//2+1,k+1): #iは取る回数
        suteru = k-i
        for j in range(i+1):
          a = A[N-j:N+i-j]
          a.sort()
          ans = max(ans,sum(a[suteru:]))
  return ans solve ans = 0 ans 0 N, K = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split K V = list(map(int, input().split())) V list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split A = V[:]*2 A V[:]*2 V[:] V : 2 for k in range(K,-1,-1): #kは操作回数
    if k>=N:
      suteru = k-N
      a = V[:]
      a.sort()
      ans = max(ans,sum(a[suteru:]))
    else:
      for i in range(k//2+1,k+1): #iは取る回数
        suteru = k-i
        for j in range(i+1):
          a = A[N-j:N+i-j]
          a.sort()
          ans = max(ans,sum(a[suteru:]))
   k range(K,-1,-1) range K -1 -1 if k>=N:
      suteru = k-N
      a = V[:]
      a.sort()
      ans = max(ans,sum(a[suteru:]))
    else:
      for i in range(k//2+1,k+1): #iは取る回数
        suteru = k-i
        for j in range(i+1):
          a = A[N-j:N+i-j]
          a.sort()
          ans = max(ans,sum(a[suteru:]))
   k>=N k N suteru = k-N suteru k-N k N a = V[:] a V[:] V : a.sort() a.sort a sort ans = max(ans,sum(a[suteru:])) ans max(ans,sum(a[suteru:])) max ans sum(a[suteru:]) sum a[suteru:] a suteru: suteru for i in range(k//2+1,k+1): #iは取る回数
        suteru = k-i
        for j in range(i+1):
          a = A[N-j:N+i-j]
          a.sort()
          ans = max(ans,sum(a[suteru:]))
   i range(k//2+1,k+1) range k//2+1 k//2 k 2 1 k+1 k 1 suteru = k-i suteru k-i k i for j in range(i+1):
          a = A[N-j:N+i-j]
          a.sort()
          ans = max(ans,sum(a[suteru:]))
   j range(i+1) range i+1 i 1 a = A[N-j:N+i-j] a A[N-j:N+i-j] A N-j:N+i-j N-j N j N+i-j N+i N i j a.sort() a.sort a sort ans = max(ans,sum(a[suteru:])) ans max(ans,sum(a[suteru:])) max ans sum(a[suteru:]) sum a[suteru:] a suteru: suteru return ans ans print(solve()) print solve() solve def solve():
  ans = 0
  N, K = map(int, input().split())
  V = list(map(int, input().split()))
  A = V[:]*2
  for k in range(K,-1,-1): #kは操作回数
    if k>=N:
      suteru = k-N
      a = V[:]
      a.sort()
      ans = max(ans,sum(a[suteru:]))
    else:
      for i in range(k//2+1,k+1): #iは取る回数
        suteru = k-i
        for j in range(i+1):
          a = A[N-j:N+i-j]
          a.sort()
          ans = max(ans,sum(a[suteru:]))
  return ans def solve():
  ans = 0
  N, K = map(int, input().split())
  V = list(map(int, input().split()))
  A = V[:]*2
  for k in range(K,-1,-1): #kは操作回数
    if k>=N:
      suteru = k-N
      a = V[:]
      a.sort()
      ans = max(ans,sum(a[suteru:]))
    else:
      for i in range(k//2+1,k+1): #iは取る回数
        suteru = k-i
        for j in range(i+1):
          a = A[N-j:N+i-j]
          a.sort()
          ans = max(ans,sum(a[suteru:]))
  return ans solve
def solve():
  ans = 0
  N, K = map(int, input().split())
  V = list(map(int, input().split()))
  A = V[:]*2
  for k in range(K,-1,-1): #kは操作回数
    if k>=N:
      suteru = k-N
      a = V[:]
      a.sort()
      ans = max(ans,sum(a[suteru:]))
    else:
      for i in range(k//2+1,k+1): #iは取る回数
        suteru = k-i
        for j in range(i+1):
          a = A[N-j:N+i-j]
          a.sort()
          ans = max(ans,sum(a[suteru:]))
  return ans
print(solve())
