def main():
    n, k = map(int, input().split())
    v = [int(x) for x in input().split()]
    
    ans = 0
    r = min([n, k])
    for i in range(r+1):
        for j in range(r+1-i):
            sub = sum(v[:i])+sum(v[n-j:n])
            minus = []
            for l in range(n):
                if (l < i or n-j < l) and v[l] < 0:
                    minus.append(v[l])
            minus.sort()
            sub -= sum(minus[:min([len(minus), k-i-j])])
            if ans < sub:
                ans = sub
        
    print(ans)

if __name__ == "__main__":
    main() def main():
    n, k = map(int, input().split())
    v = [int(x) for x in input().split()]
    
    ans = 0
    r = min([n, k])
    for i in range(r+1):
        for j in range(r+1-i):
            sub = sum(v[:i])+sum(v[n-j:n])
            minus = []
            for l in range(n):
                if (l < i or n-j < l) and v[l] < 0:
                    minus.append(v[l])
            minus.sort()
            sub -= sum(minus[:min([len(minus), k-i-j])])
            if ans < sub:
                ans = sub
        
    print(ans) main n, k = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split k int(x) for x in input().split() for x in input().split() x input().split() ().split () input split for x in input().split() int(x) int x v = [int(x) for x in input().split()] v [int(x) for x in input().split()] ans = 0 ans 0 r = min([n, k]) r min([n, k]) min [n, k] n k for i in range(r+1):
        for j in range(r+1-i):
            sub = sum(v[:i])+sum(v[n-j:n])
            minus = []
            for l in range(n):
                if (l < i or n-j < l) and v[l] < 0:
                    minus.append(v[l])
            minus.sort()
            sub -= sum(minus[:min([len(minus), k-i-j])])
            if ans < sub:
                ans = sub
        
     i range(r+1) range r+1 r 1 for j in range(r+1-i):
            sub = sum(v[:i])+sum(v[n-j:n])
            minus = []
            for l in range(n):
                if (l < i or n-j < l) and v[l] < 0:
                    minus.append(v[l])
            minus.sort()
            sub -= sum(minus[:min([len(minus), k-i-j])])
            if ans < sub:
                ans = sub
        
     j range(r+1-i) range r+1-i r+1 r 1 i sub = sum(v[:i])+sum(v[n-j:n]) sub sum(v[:i])+sum(v[n-j:n]) sum(v[:i]) sum v[:i] v :i i sum(v[n-j:n]) sum v[n-j:n] v n-j:n n-j n j n minus = [] minus [] for l in range(n):
                if (l < i or n-j < l) and v[l] < 0:
                    minus.append(v[l])
             l range(n) range n if (l < i or n-j < l) and v[l] < 0:
                    minus.append(v[l])
             (l < i or n-j < l) and v[l] < 0 l < i or n-j < l l < i l i n-j < l n-j n j l v[l] < 0 v[l] v l 0 minus.append(v[l]) minus.append minus append v[l] v l minus.sort() minus.sort minus sort sub -= sum(minus[:min([len(minus), k-i-j])]) sub sum(minus[:min([len(minus), k-i-j])]) sum minus[:min([len(minus), k-i-j])] minus :min([len(minus), k-i-j]) min([len(minus), k-i-j]) min [len(minus), k-i-j] len(minus) len minus k-i-j k-i k i j if ans < sub:
                ans = sub
        
     ans < sub ans sub ans = sub ans sub print(ans) print ans if __name__ == "__main__":
    main() __name__ == "__main__" __name__ "__main__" main() main def main():
    n, k = map(int, input().split())
    v = [int(x) for x in input().split()]
    
    ans = 0
    r = min([n, k])
    for i in range(r+1):
        for j in range(r+1-i):
            sub = sum(v[:i])+sum(v[n-j:n])
            minus = []
            for l in range(n):
                if (l < i or n-j < l) and v[l] < 0:
                    minus.append(v[l])
            minus.sort()
            sub -= sum(minus[:min([len(minus), k-i-j])])
            if ans < sub:
                ans = sub
        
    print(ans) def main():
    n, k = map(int, input().split())
    v = [int(x) for x in input().split()]
    
    ans = 0
    r = min([n, k])
    for i in range(r+1):
        for j in range(r+1-i):
            sub = sum(v[:i])+sum(v[n-j:n])
            minus = []
            for l in range(n):
                if (l < i or n-j < l) and v[l] < 0:
                    minus.append(v[l])
            minus.sort()
            sub -= sum(minus[:min([len(minus), k-i-j])])
            if ans < sub:
                ans = sub
        
    print(ans) main
def main():
    n, k = map(int, input().split())
    v = [int(x) for x in input().split()]
    
    ans = 0
    r = min([n, k])
    for i in range(r+1):
        for j in range(r+1-i):
            sub = sum(v[:i])+sum(v[n-j:n])
            minus = []
            for l in range(n):
                if (l < i or n-j < l) and v[l] < 0:
                    minus.append(v[l])
            minus.sort()
            sub -= sum(minus[:min([len(minus), k-i-j])])
            if ans < sub:
                ans = sub
        
    print(ans)

if __name__ == "__main__":
    main()