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

ans = - 10 ** 19
# i: Dから取り出す宝石の個数
for i in range(min(k + 1, n + 1)):
  # j: 左からとる個数(i-jが右からとる個数)
  for j in range(i + 1):
    inhands = V[:j] + V[n - i + j:]
    inhands.sort()
    remnum = k - i
    val = 0
    for h in inhands:
      if h < 0 and remnum > 0:
        remnum -= 1
      else:
        val += h
    ans = max(ans, val)
print(ans) 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 ans = - 10 ** 19 ans - 10 ** 19 - 10 19 for i in range(min(k + 1, n + 1)):
  # j: 左からとる個数(i-jが右からとる個数)
  for j in range(i + 1):
    inhands = V[:j] + V[n - i + j:]
    inhands.sort()
    remnum = k - i
    val = 0
    for h in inhands:
      if h < 0 and remnum > 0:
        remnum -= 1
      else:
        val += h
    ans = max(ans, val) i range(min(k + 1, n + 1)) range min(k + 1, n + 1) min k + 1 k 1 n + 1 n 1 for j in range(i + 1):
    inhands = V[:j] + V[n - i + j:]
    inhands.sort()
    remnum = k - i
    val = 0
    for h in inhands:
      if h < 0 and remnum > 0:
        remnum -= 1
      else:
        val += h
    ans = max(ans, val) j range(i + 1) range i + 1 i 1 inhands = V[:j] + V[n - i + j:] inhands V[:j] + V[n - i + j:] V[:j] V :j j V[n - i + j:] V n - i + j: n - i + j n - i n i j inhands.sort() inhands.sort inhands sort remnum = k - i remnum k - i k i val = 0 val 0 for h in inhands:
      if h < 0 and remnum > 0:
        remnum -= 1
      else:
        val += h
     h inhands if h < 0 and remnum > 0:
        remnum -= 1
      else:
        val += h
     h < 0 and remnum > 0 h < 0 h 0 remnum > 0 remnum 0 remnum -= 1 remnum 1 val += h val h ans = max(ans, val) ans max(ans, val) max ans val print(ans) print ans V = list(map(int, input().split())) list(map(int, input().split())) V val += h h val remnum -= 1 1 remnum val = 0 0 val k = map(int, input().split()) map(int, input().split()) k inhands = V[:j] + V[n - i + j:] V[:j] + V[n - i + j:] inhands ans = - 10 ** 19 - 10 ** 19 ans remnum = k - i k - i remnum ans = max(ans, val) max(ans, val) ans n, k = map(int, input().split()) map(int, input().split()) n
n, k = map(int, input().split())
V = list(map(int, input().split()))

ans = - 10 ** 19
# i: Dから取り出す宝石の個数
for i in range(min(k + 1, n + 1)):
  # j: 左からとる個数(i-jが右からとる個数)
  for j in range(i + 1):
    inhands = V[:j] + V[n - i + j:]
    inhands.sort()
    remnum = k - i
    val = 0
    for h in inhands:
      if h < 0 and remnum > 0:
        remnum -= 1
      else:
        val += h
    ans = max(ans, val)
print(ans)