'''
研究室PCでの解答
'''
import math
#import numpy as np
import queue
import bisect
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)
mod = 10**9+7 #998244353
dir = [(-1,0),(1,0),(0,-1),(0,1)]
alp = "abcdefghijklmnopqrstuvwxyz"

def main():
    n,k = map(int,ipt().split())
    v = [int(i) for i in ipt().split()]
    rv = v[::-1]
    ma = 0
    for ai in range(n+1):
        for bi in range(n-ai+1):
            d = k-ai-bi
            if d < 0:
                continue
            vs = v[:ai:]+rv[:bi:]
            vs.sort(reverse=True)
            for i in range(min(ai+bi,d)):
                if vs[-1] >= 0:
                    break
                else:
                    vs.pop()
            nm = sum(vs)
            if ma < nm:
                ma = nm

    print(ma)



    return None

if __name__ == '__main__':
    main() '''
研究室PCでの解答
''' import math math import queue queue import bisect bisect from collections import deque,defaultdict import heapq as hpq heapq from sys import stdin,setrecursionlimit ipt = stdin.readline ipt stdin.readline stdin readline setrecursionlimit(10**7) setrecursionlimit 10**7 10 7 mod = 10**9+7 mod 10**9+7 10**9 10 9 7 dir = [(-1,0),(1,0),(0,-1),(0,1)] dir [(-1,0),(1,0),(0,-1),(0,1)] (-1,0) -1 0 (1,0) 1 0 (0,-1) 0 -1 (0,1) 0 1 alp = "abcdefghijklmnopqrstuvwxyz" alp "abcdefghijklmnopqrstuvwxyz" def main():
    n,k = map(int,ipt().split())
    v = [int(i) for i in ipt().split()]
    rv = v[::-1]
    ma = 0
    for ai in range(n+1):
        for bi in range(n-ai+1):
            d = k-ai-bi
            if d < 0:
                continue
            vs = v[:ai:]+rv[:bi:]
            vs.sort(reverse=True)
            for i in range(min(ai+bi,d)):
                if vs[-1] >= 0:
                    break
                else:
                    vs.pop()
            nm = sum(vs)
            if ma < nm:
                ma = nm

    print(ma)



    return None main n,k = map(int,ipt().split()) n map(int,ipt().split()) map int ipt().split() ().split () ipt split k int(i) for i in ipt().split() for i in ipt().split() i ipt().split() ().split () ipt split for i in ipt().split() int(i) int i v = [int(i) for i in ipt().split()] v [int(i) for i in ipt().split()] rv = v[::-1] rv v[::-1] v ::-1 -1 ma = 0 ma 0 for ai in range(n+1):
        for bi in range(n-ai+1):
            d = k-ai-bi
            if d < 0:
                continue
            vs = v[:ai:]+rv[:bi:]
            vs.sort(reverse=True)
            for i in range(min(ai+bi,d)):
                if vs[-1] >= 0:
                    break
                else:
                    vs.pop()
            nm = sum(vs)
            if ma < nm:
                ma = nm

     ai range(n+1) range n+1 n 1 for bi in range(n-ai+1):
            d = k-ai-bi
            if d < 0:
                continue
            vs = v[:ai:]+rv[:bi:]
            vs.sort(reverse=True)
            for i in range(min(ai+bi,d)):
                if vs[-1] >= 0:
                    break
                else:
                    vs.pop()
            nm = sum(vs)
            if ma < nm:
                ma = nm

     bi range(n-ai+1) range n-ai+1 n-ai n ai 1 d = k-ai-bi d k-ai-bi k-ai k ai bi if d < 0:
                continue
             d < 0 d 0 continue vs = v[:ai:]+rv[:bi:] vs v[:ai:]+rv[:bi:] v[:ai:] v :ai: ai rv[:bi:] rv :bi: bi vs.sort(reverse=True) vs.sort vs sort reverse=True reverse True for i in range(min(ai+bi,d)):
                if vs[-1] >= 0:
                    break
                else:
                    vs.pop()
             i range(min(ai+bi,d)) range min(ai+bi,d) min ai+bi ai bi d if vs[-1] >= 0:
                    break
                else:
                    vs.pop()
             vs[-1] >= 0 vs[-1] vs -1 0 break vs.pop() vs.pop vs pop nm = sum(vs) nm sum(vs) sum vs if ma < nm:
                ma = nm

     ma < nm ma nm ma = nm ma nm print(ma) print ma return None None if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main def main():
    n,k = map(int,ipt().split())
    v = [int(i) for i in ipt().split()]
    rv = v[::-1]
    ma = 0
    for ai in range(n+1):
        for bi in range(n-ai+1):
            d = k-ai-bi
            if d < 0:
                continue
            vs = v[:ai:]+rv[:bi:]
            vs.sort(reverse=True)
            for i in range(min(ai+bi,d)):
                if vs[-1] >= 0:
                    break
                else:
                    vs.pop()
            nm = sum(vs)
            if ma < nm:
                ma = nm

    print(ma)



    return None def main():
    n,k = map(int,ipt().split())
    v = [int(i) for i in ipt().split()]
    rv = v[::-1]
    ma = 0
    for ai in range(n+1):
        for bi in range(n-ai+1):
            d = k-ai-bi
            if d < 0:
                continue
            vs = v[:ai:]+rv[:bi:]
            vs.sort(reverse=True)
            for i in range(min(ai+bi,d)):
                if vs[-1] >= 0:
                    break
                else:
                    vs.pop()
            nm = sum(vs)
            if ma < nm:
                ma = nm

    print(ma)



    return None main mod = 10**9+7 10**9+7 mod alp = "abcdefghijklmnopqrstuvwxyz" "abcdefghijklmnopqrstuvwxyz" alp ipt = stdin.readline stdin.readline ipt dir = [(-1,0),(1,0),(0,-1),(0,1)] [(-1,0),(1,0),(0,-1),(0,1)] dir
'''
研究室PCでの解答
'''
import math
#import numpy as np
import queue
import bisect
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)
mod = 10**9+7 #998244353
dir = [(-1,0),(1,0),(0,-1),(0,1)]
alp = "abcdefghijklmnopqrstuvwxyz"

def main():
    n,k = map(int,ipt().split())
    v = [int(i) for i in ipt().split()]
    rv = v[::-1]
    ma = 0
    for ai in range(n+1):
        for bi in range(n-ai+1):
            d = k-ai-bi
            if d < 0:
                continue
            vs = v[:ai:]+rv[:bi:]
            vs.sort(reverse=True)
            for i in range(min(ai+bi,d)):
                if vs[-1] >= 0:
                    break
                else:
                    vs.pop()
            nm = sum(vs)
            if ma < nm:
                ma = nm

    print(ma)



    return None

if __name__ == '__main__':
    main()
