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

a=list(map(int,input().split()))
a_reverse=list(reversed(a))
b=sorted(a)
s=sum(a)

ans=[]

for i in range(k+1):
  if i>n:
    I=i-n
    for j in range(I): 
      if j<n:
        ans1=s-b[j]
    ans.append(ans1)
  elif i==n:
    ans.append(s)
  elif i==0:
    ans.append(0)
  else:
    for h in range(i+1):
      H=i-h
      c=[]
      for x in range(h):
        c.append(a[x])
      for y in range(H):
        c.append(a_reverse[y])
        
      c.sort()
      S=sum(c)
      for g in range(1,k-i+1):
        if g<=i:
          if c[g-1]<0:
            S-=c[g-1]

      ans.append(S)
      
print(max(ans)) n,k=map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split k a=list(map(int,input().split())) a list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split a_reverse=list(reversed(a)) a_reverse list(reversed(a)) list reversed(a) reversed a b=sorted(a) b sorted(a) sorted a s=sum(a) s sum(a) sum a ans=[] ans [] for i in range(k+1):
  if i>n:
    I=i-n
    for j in range(I): 
      if j<n:
        ans1=s-b[j]
    ans.append(ans1)
  elif i==n:
    ans.append(s)
  elif i==0:
    ans.append(0)
  else:
    for h in range(i+1):
      H=i-h
      c=[]
      for x in range(h):
        c.append(a[x])
      for y in range(H):
        c.append(a_reverse[y])
        
      c.sort()
      S=sum(c)
      for g in range(1,k-i+1):
        if g<=i:
          if c[g-1]<0:
            S-=c[g-1]

      ans.append(S)
       i range(k+1) range k+1 k 1 if i>n:
    I=i-n
    for j in range(I): 
      if j<n:
        ans1=s-b[j]
    ans.append(ans1)
  elif i==n:
    ans.append(s)
  elif i==0:
    ans.append(0)
  else:
    for h in range(i+1):
      H=i-h
      c=[]
      for x in range(h):
        c.append(a[x])
      for y in range(H):
        c.append(a_reverse[y])
        
      c.sort()
      S=sum(c)
      for g in range(1,k-i+1):
        if g<=i:
          if c[g-1]<0:
            S-=c[g-1]

      ans.append(S)
       i>n i n I=i-n I i-n i n for j in range(I): 
      if j<n:
        ans1=s-b[j]
     j range(I) range I if j<n:
        ans1=s-b[j]
     j<n j n ans1=s-b[j] ans1 s-b[j] s b[j] b j ans.append(ans1) ans.append ans append ans1 elif i==n:
    ans.append(s)
   i==n i n ans.append(s) ans.append ans append s elif i==0:
    ans.append(0)
   i==0 i 0 ans.append(0) ans.append ans append 0 for h in range(i+1):
      H=i-h
      c=[]
      for x in range(h):
        c.append(a[x])
      for y in range(H):
        c.append(a_reverse[y])
        
      c.sort()
      S=sum(c)
      for g in range(1,k-i+1):
        if g<=i:
          if c[g-1]<0:
            S-=c[g-1]

      ans.append(S)
       h range(i+1) range i+1 i 1 H=i-h H i-h i h c=[] c [] for x in range(h):
        c.append(a[x])
       x range(h) range h c.append(a[x]) c.append c append a[x] a x for y in range(H):
        c.append(a_reverse[y])
        
       y range(H) range H c.append(a_reverse[y]) c.append c append a_reverse[y] a_reverse y c.sort() c.sort c sort S=sum(c) S sum(c) sum c for g in range(1,k-i+1):
        if g<=i:
          if c[g-1]<0:
            S-=c[g-1]

       g range(1,k-i+1) range 1 k-i+1 k-i k i 1 if g<=i:
          if c[g-1]<0:
            S-=c[g-1]

       g<=i g i if c[g-1]<0:
            S-=c[g-1]

       c[g-1]<0 c[g-1] c g-1 g 1 0 S-=c[g-1] S c[g-1] c g-1 g 1 ans.append(S) ans.append ans append S print(max(ans)) print max(ans) max ans H=i-h i-h H S-=c[g-1] c[g-1] S S=sum(c) sum(c) S s=sum(a) sum(a) s I=i-n i-n I k=map(int,input().split()) map(int,input().split()) k b=sorted(a) sorted(a) b a=list(map(int,input().split())) list(map(int,input().split())) a c=[] [] c ans1=s-b[j] s-b[j] ans1 a_reverse=list(reversed(a)) list(reversed(a)) a_reverse ans=[] [] ans n,k=map(int,input().split()) map(int,input().split()) n
n,k=map(int,input().split())

a=list(map(int,input().split()))
a_reverse=list(reversed(a))
b=sorted(a)
s=sum(a)

ans=[]

for i in range(k+1):
  if i>n:
    I=i-n
    for j in range(I): 
      if j<n:
        ans1=s-b[j]
    ans.append(ans1)
  elif i==n:
    ans.append(s)
  elif i==0:
    ans.append(0)
  else:
    for h in range(i+1):
      H=i-h
      c=[]
      for x in range(h):
        c.append(a[x])
      for y in range(H):
        c.append(a_reverse[y])
        
      c.sort()
      S=sum(c)
      for g in range(1,k-i+1):
        if g<=i:
          if c[g-1]<0:
            S-=c[g-1]

      ans.append(S)
      
print(max(ans))