jewel, query = map(int, input().split())
t = min(jewel, query)
dq = [int(i) for i in input().split()]
ans = []

for i in range(t+1):
  for j in range(i+1):
    have = dq[:j] + dq[(jewel-i+j):]
    drop = query - len(have)

    for k in range(drop):
      if not have:
        break
      
      cand = min(have)
      if cand < 0:
        have.remove(cand)
      else:
        break
        
    ans.append(sum(have))
    
print(max(ans)) jewel, query = map(int, input().split()) jewel map(int, input().split()) map int input().split() ().split () input split query t = min(jewel, query) t min(jewel, query) min jewel query int(i) for i in input().split() for i in input().split() i input().split() ().split () input split for i in input().split() int(i) int i dq = [int(i) for i in input().split()] dq [int(i) for i in input().split()] ans = [] ans [] for i in range(t+1):
  for j in range(i+1):
    have = dq[:j] + dq[(jewel-i+j):]
    drop = query - len(have)

    for k in range(drop):
      if not have:
        break
      
      cand = min(have)
      if cand < 0:
        have.remove(cand)
      else:
        break
        
    ans.append(sum(have))
     i range(t+1) range t+1 t 1 for j in range(i+1):
    have = dq[:j] + dq[(jewel-i+j):]
    drop = query - len(have)

    for k in range(drop):
      if not have:
        break
      
      cand = min(have)
      if cand < 0:
        have.remove(cand)
      else:
        break
        
    ans.append(sum(have))
     j range(i+1) range i+1 i 1 have = dq[:j] + dq[(jewel-i+j):] have dq[:j] + dq[(jewel-i+j):] dq[:j] dq :j j dq[(jewel-i+j):] dq (jewel-i+j): jewel-i+j jewel-i jewel i j drop = query - len(have) drop query - len(have) query len(have) len have for k in range(drop):
      if not have:
        break
      
      cand = min(have)
      if cand < 0:
        have.remove(cand)
      else:
        break
        
     k range(drop) range drop if not have:
        break
      
       not have have break cand = min(have) cand min(have) min have if cand < 0:
        have.remove(cand)
      else:
        break
        
     cand < 0 cand 0 have.remove(cand) have.remove have remove cand break ans.append(sum(have)) ans.append ans append sum(have) sum have print(max(ans)) print max(ans) max ans drop = query - len(have) query - len(have) drop jewel, query = map(int, input().split()) map(int, input().split()) jewel query = map(int, input().split()) map(int, input().split()) query t = min(jewel, query) min(jewel, query) t have = dq[:j] + dq[(jewel-i+j):] dq[:j] + dq[(jewel-i+j):] have ans = [] [] ans dq = [int(i) for i in input().split()] [int(i) for i in input().split()] dq cand = min(have) min(have) cand
jewel, query = map(int, input().split())
t = min(jewel, query)
dq = [int(i) for i in input().split()]
ans = []

for i in range(t+1):
  for j in range(i+1):
    have = dq[:j] + dq[(jewel-i+j):]
    drop = query - len(have)

    for k in range(drop):
      if not have:
        break
      
      cand = min(have)
      if cand < 0:
        have.remove(cand)
      else:
        break
        
    ans.append(sum(have))
    
print(max(ans))