import sys
sys.setrecursionlimit(10000000)

n,k = map(int,input().split())
v = list(map(int,input().split()))
ans=0
for l in range(k+1):
    for r in range(k-l+1):
        if l+r > n :break

        d=k-l-r
        now=0
        s=[]

        for i in range(l):
            now+=v[i]
            s.append(v[i])

        for i in range(n-r,n):
            now+=v[i]
            s.append(v[i])

        s.sort()
        for i in range(d):
            if(i >= len(s)):break
            if s[i] > 0 :break

            now -= s[i]

        ans=max(now,ans)
print(ans) import sys sys sys.setrecursionlimit(10000000) sys.setrecursionlimit sys setrecursionlimit 10000000 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=0 ans 0 for l in range(k+1):
    for r in range(k-l+1):
        if l+r > n :break

        d=k-l-r
        now=0
        s=[]

        for i in range(l):
            now+=v[i]
            s.append(v[i])

        for i in range(n-r,n):
            now+=v[i]
            s.append(v[i])

        s.sort()
        for i in range(d):
            if(i >= len(s)):break
            if s[i] > 0 :break

            now -= s[i]

        ans=max(now,ans) l range(k+1) range k+1 k 1 for r in range(k-l+1):
        if l+r > n :break

        d=k-l-r
        now=0
        s=[]

        for i in range(l):
            now+=v[i]
            s.append(v[i])

        for i in range(n-r,n):
            now+=v[i]
            s.append(v[i])

        s.sort()
        for i in range(d):
            if(i >= len(s)):break
            if s[i] > 0 :break

            now -= s[i]

        ans=max(now,ans) r range(k-l+1) range k-l+1 k-l k l 1 if l+r > n :break

         l+r > n l+r l r n d=k-l-r d k-l-r k-l k l r now=0 now 0 s=[] s [] for i in range(l):
            now+=v[i]
            s.append(v[i])

         i range(l) range l now+=v[i] now v[i] v i s.append(v[i]) s.append s append v[i] v i for i in range(n-r,n):
            now+=v[i]
            s.append(v[i])

         i range(n-r,n) range n-r n r n now+=v[i] now v[i] v i s.append(v[i]) s.append s append v[i] v i s.sort() s.sort s sort for i in range(d):
            if(i >= len(s)):break
            if s[i] > 0 :break

            now -= s[i]

         i range(d) range d if(i >= len(s)):break
             i >= len(s) i len(s) len s if s[i] > 0 :break

             s[i] > 0 s[i] s i 0 now -= s[i] now s[i] s i ans=max(now,ans) ans max(now,ans) max now ans print(ans) print ans ans=0 0 ans ans=max(now,ans) max(now,ans) ans s=[] [] s k = map(int,input().split()) map(int,input().split()) k now+=v[i] v[i] now n,k = map(int,input().split()) map(int,input().split()) n now=0 0 now now+=v[i] v[i] now v = list(map(int,input().split())) list(map(int,input().split())) v d=k-l-r k-l-r d now -= s[i] s[i] now
import sys
sys.setrecursionlimit(10000000)

n,k = map(int,input().split())
v = list(map(int,input().split()))
ans=0
for l in range(k+1):
    for r in range(k-l+1):
        if l+r > n :break

        d=k-l-r
        now=0
        s=[]

        for i in range(l):
            now+=v[i]
            s.append(v[i])

        for i in range(n-r,n):
            now+=v[i]
            s.append(v[i])

        s.sort()
        for i in range(d):
            if(i >= len(s)):break
            if s[i] > 0 :break

            now -= s[i]

        ans=max(now,ans)
print(ans)