from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import permutations,combinations
from collections import defaultdict,Counter
from bisect import bisect_left,bisect_right
# from math import gcd,ceil,floor,factorial
# from fractions import gcd
from functools import reduce
from pprint import pprint

def myinput():
    return map(int,input().split())

def mylistinput(n):
    return [ list(myinput()) for _ in range(n) ]

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col,reverse_flag):
    data.sort(key=lambda x:x[col],reverse=reverse_flag)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(" ")
        elif type(ls[0])==str:
            print(" ".join(ls))
        elif type(ls[0])==int:
            print(" ".join(map(str,ls)))
        else:
            print("Output Error")
    else:
        if len(ls)==0:
            print("")
        elif type(ls[0])==str:
            print("".join(ls))
        elif type(ls[0])==int:
            print("".join(map(str,ls)))
        else:
            print("Output Error")

# ----- heapq ここから-----
import heapq
class Reverse:
    def __init__(self, val):
        self.val = val
        
    def __lt__(self, other):
        return self.val > other.val
        
    def __repr__(self):
        return repr(self.val)
    
class Heapq:
    def __init__(self, arr, desc = False):
        if desc:
            for i in range(len(arr)):
                arr[i] = Reverse(arr[i])
        self.desc = desc
        self.hq = arr
        heapq.heapify(self.hq)
 
    def pop(self):
        if self.desc: return heapq.heappop(self.hq).val
        else: return heapq.heappop(self.hq)
 
    def push(self, a):
        if self.desc: heapq.heappush(self.hq, Reverse(a))
        else: heapq.heappush(self.hq, a)
 
    def top(self):
        if self.desc: self.hq[0].val
        else: return self.hq[0]
# ----- heapq ここまで-----

n,k = myinput()
v = list(myinput())
vr = v[::-1]

ls = [-1,-1]
ans = -float("inf")
for a in range(k+1):
    for b in range(min(k-a+1,n-a+1)):
        have = []
        have.extend( v[:a] )
        have.extend( vr[:b] )
        p = [ i for i in have if i>=0 ]
        m = [ i for i in have if i<0 ]
        m.sort()
        r = k - a - b
        m = m[r:]
        ans_tmp = sum(p)+sum(m)
        if ans<ans_tmp:
            ls[0] = a
            ls[1] = b
        ans = max(ans,ans_tmp)
# print(ls)
print(ans) from collections import deque from heapq import heapify,heappop,heappush,heappushpop from copy import copy,deepcopy from itertools import permutations,combinations from collections import defaultdict,Counter from bisect import bisect_left,bisect_right from functools import reduce from pprint import pprint def myinput():
    return map(int,input().split()) myinput return map(int,input().split()) map(int,input().split()) map int input().split() ().split () input split def mylistinput(n):
    return [ list(myinput()) for _ in range(n) ] mylistinput list(myinput()) for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) list(myinput()) list myinput() myinput return [ list(myinput()) for _ in range(n) ] [ list(myinput()) for _ in range(n) ] n n def mycol(data,col):
    return [ row[col] for row in data ] mycol row[col] for row in data for row in data row data for row in data row[col] row col return [ row[col] for row in data ] [ row[col] for row in data ] data data col col def mysort(data,col,reverse_flag):
    data.sort(key=lambda x:x[col],reverse=reverse_flag)
    return data mysort data.sort(key=lambda x:x[col],reverse=reverse_flag) data.sort data sort key=lambda x:x[col] key lambda x:x[col] x[col] x col x reverse=reverse_flag reverse reverse_flag return data data data data col col reverse_flag reverse_flag def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M mymax M = -1*float("inf") M -1*float("inf") -1 float("inf") float "inf" for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
     i range(len(data)) range len(data) len data m = max(data[i]) m max(data[i]) max data[i] data i M = max(M,m) M max(M,m) max M m return M M data data def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m mymin m = float("inf") m float("inf") float "inf" for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
     i range(len(data)) range len(data) len data M = min(data[i]) M min(data[i]) min data[i] data i m = min(m,M) m min(m,M) min m M return m m data data def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(" ")
        elif type(ls[0])==str:
            print(" ".join(ls))
        elif type(ls[0])==int:
            print(" ".join(map(str,ls)))
        else:
            print("Output Error")
    else:
        if len(ls)==0:
            print("")
        elif type(ls[0])==str:
            print("".join(ls))
        elif type(ls[0])==int:
            print("".join(map(str,ls)))
        else:
            print("Output Error")

# ----- heapq ここから----- myoutput if space:
        if len(ls)==0:
            print(" ")
        elif type(ls[0])==str:
            print(" ".join(ls))
        elif type(ls[0])==int:
            print(" ".join(map(str,ls)))
        else:
            print("Output Error")
    else:
        if len(ls)==0:
            print("")
        elif type(ls[0])==str:
            print("".join(ls))
        elif type(ls[0])==int:
            print("".join(map(str,ls)))
        else:
            print("Output Error")

# ----- heapq ここから----- space if len(ls)==0:
            print(" ")
        elif type(ls[0])==str:
            print(" ".join(ls))
        elif type(ls[0])==int:
            print(" ".join(map(str,ls)))
        else:
            print("Output Error")
     len(ls)==0 len(ls) len ls 0 print(" ") print " " elif type(ls[0])==str:
            print(" ".join(ls))
         type(ls[0])==str type(ls[0]) type ls[0] ls 0 str print(" ".join(ls)) print " ".join(ls) " ".join " " join ls elif type(ls[0])==int:
            print(" ".join(map(str,ls)))
         type(ls[0])==int type(ls[0]) type ls[0] ls 0 int print(" ".join(map(str,ls))) print " ".join(map(str,ls)) " ".join " " join map(str,ls) map str ls print("Output Error") print "Output Error" if len(ls)==0:
            print("")
        elif type(ls[0])==str:
            print("".join(ls))
        elif type(ls[0])==int:
            print("".join(map(str,ls)))
        else:
            print("Output Error")

# ----- heapq ここから----- len(ls)==0 len(ls) len ls 0 print("") print "" elif type(ls[0])==str:
            print("".join(ls))
         type(ls[0])==str type(ls[0]) type ls[0] ls 0 str print("".join(ls)) print "".join(ls) "".join "" join ls elif type(ls[0])==int:
            print("".join(map(str,ls)))
         type(ls[0])==int type(ls[0]) type ls[0] ls 0 int print("".join(map(str,ls))) print "".join(map(str,ls)) "".join "" join map(str,ls) map str ls print("Output Error") print "Output Error" ls ls space=True space True import heapq heapq class Reverse:
    def __init__(self, val):
        self.val = val
        
    def __lt__(self, other):
        return self.val > other.val
        
    def __repr__(self):
        return repr(self.val)
     Reverse def __init__(self, val):
        self.val = val
        
     __init__ self.val = val self.val self val val self self val val def __lt__(self, other):
        return self.val > other.val
        
     __lt__ return self.val > other.val self.val > other.val self.val self val other.val other val self self other other def __repr__(self):
        return repr(self.val)
     __repr__ return repr(self.val) repr(self.val) repr self.val self val self self class Heapq:
    def __init__(self, arr, desc = False):
        if desc:
            for i in range(len(arr)):
                arr[i] = Reverse(arr[i])
        self.desc = desc
        self.hq = arr
        heapq.heapify(self.hq)
 
    def pop(self):
        if self.desc: return heapq.heappop(self.hq).val
        else: return heapq.heappop(self.hq)
 
    def push(self, a):
        if self.desc: heapq.heappush(self.hq, Reverse(a))
        else: heapq.heappush(self.hq, a)
 
    def top(self):
        if self.desc: self.hq[0].val
        else: return self.hq[0]
# ----- heapq ここまで----- Heapq def __init__(self, arr, desc = False):
        if desc:
            for i in range(len(arr)):
                arr[i] = Reverse(arr[i])
        self.desc = desc
        self.hq = arr
        heapq.heapify(self.hq)
 
     __init__ if desc:
            for i in range(len(arr)):
                arr[i] = Reverse(arr[i])
         desc for i in range(len(arr)):
                arr[i] = Reverse(arr[i])
         i range(len(arr)) range len(arr) len arr arr[i] = Reverse(arr[i]) arr[i] arr i Reverse(arr[i]) Reverse arr[i] arr i self.desc = desc self.desc self desc desc self.hq = arr self.hq self hq arr heapq.heapify(self.hq) heapq.heapify heapq heapify self.hq self hq self self arr arr desc = False desc False def pop(self):
        if self.desc: return heapq.heappop(self.hq).val
        else: return heapq.heappop(self.hq)
 
     pop if self.desc: return heapq.heappop(self.hq).val
        else: return heapq.heappop(self.hq)
 
     self.desc self desc self self def push(self, a):
        if self.desc: heapq.heappush(self.hq, Reverse(a))
        else: heapq.heappush(self.hq, a)
 
     push if self.desc: heapq.heappush(self.hq, Reverse(a))
        else: heapq.heappush(self.hq, a)
 
     self.desc self desc self self a a def top(self):
        if self.desc: self.hq[0].val
        else: return self.hq[0]
# ----- heapq ここまで----- top if self.desc: self.hq[0].val
        else: return self.hq[0]
# ----- heapq ここまで----- self.desc self desc self self n,k = myinput() n myinput() myinput k v = list(myinput()) v list(myinput()) list myinput() myinput vr = v[::-1] vr v[::-1] v ::-1 -1 ls = [-1,-1] ls [-1,-1] -1 -1 ans = -float("inf") ans -float("inf") float("inf") float "inf" for a in range(k+1):
    for b in range(min(k-a+1,n-a+1)):
        have = []
        have.extend( v[:a] )
        have.extend( vr[:b] )
        p = [ i for i in have if i>=0 ]
        m = [ i for i in have if i<0 ]
        m.sort()
        r = k - a - b
        m = m[r:]
        ans_tmp = sum(p)+sum(m)
        if ans<ans_tmp:
            ls[0] = a
            ls[1] = b
        ans = max(ans,ans_tmp)
# print(ls) a range(k+1) range k+1 k 1 for b in range(min(k-a+1,n-a+1)):
        have = []
        have.extend( v[:a] )
        have.extend( vr[:b] )
        p = [ i for i in have if i>=0 ]
        m = [ i for i in have if i<0 ]
        m.sort()
        r = k - a - b
        m = m[r:]
        ans_tmp = sum(p)+sum(m)
        if ans<ans_tmp:
            ls[0] = a
            ls[1] = b
        ans = max(ans,ans_tmp)
# print(ls) b range(min(k-a+1,n-a+1)) range min(k-a+1,n-a+1) min k-a+1 k-a k a 1 n-a+1 n-a n a 1 have = [] have [] have.extend( v[:a] ) have.extend have extend v[:a] v :a a have.extend( vr[:b] ) have.extend have extend vr[:b] vr :b b i for i in have if i>=0 for i in have if i>=0 i have i>=0 i 0 if i>=0 i p = [ i for i in have if i>=0 ] p [ i for i in have if i>=0 ] i for i in have if i<0 for i in have if i<0 i have i<0 i 0 if i<0 i m = [ i for i in have if i<0 ] m [ i for i in have if i<0 ] m.sort() m.sort m sort r = k - a - b r k - a - b k - a k a b m = m[r:] m m[r:] m r: r ans_tmp = sum(p)+sum(m) ans_tmp sum(p)+sum(m) sum(p) sum p sum(m) sum m if ans<ans_tmp:
            ls[0] = a
            ls[1] = b
         ans<ans_tmp ans ans_tmp ls[0] = a ls[0] ls 0 a ls[1] = b ls[1] ls 1 b ans = max(ans,ans_tmp) ans max(ans,ans_tmp) max ans ans_tmp print(ans) print ans m = [ i for i in have if i<0 ] [ i for i in have if i<0 ] m ans = -float("inf") -float("inf") ans def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m mymin n,k = myinput() myinput() n have = [] [] have m = m[r:] m[r:] m def myinput():
    return map(int,input().split()) def myinput():
    return map(int,input().split()) myinput def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(" ")
        elif type(ls[0])==str:
            print(" ".join(ls))
        elif type(ls[0])==int:
            print(" ".join(map(str,ls)))
        else:
            print("Output Error")
    else:
        if len(ls)==0:
            print("")
        elif type(ls[0])==str:
            print("".join(ls))
        elif type(ls[0])==int:
            print("".join(map(str,ls)))
        else:
            print("Output Error")

# ----- heapq ここから----- def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(" ")
        elif type(ls[0])==str:
            print(" ".join(ls))
        elif type(ls[0])==int:
            print(" ".join(map(str,ls)))
        else:
            print("Output Error")
    else:
        if len(ls)==0:
            print("")
        elif type(ls[0])==str:
            print("".join(ls))
        elif type(ls[0])==int:
            print("".join(map(str,ls)))
        else:
            print("Output Error")

# ----- heapq ここから----- myoutput ls = [-1,-1] [-1,-1] ls vr = v[::-1] v[::-1] vr def mycol(data,col):
    return [ row[col] for row in data ] def mycol(data,col):
    return [ row[col] for row in data ] mycol v = list(myinput()) list(myinput()) v r = k - a - b k - a - b r class Reverse:
    def __init__(self, val):
        self.val = val
        
    def __lt__(self, other):
        return self.val > other.val
        
    def __repr__(self):
        return repr(self.val)
     class Reverse:
    def __init__(self, val):
        self.val = val
        
    def __lt__(self, other):
        return self.val > other.val
        
    def __repr__(self):
        return repr(self.val)
     Reverse ans_tmp = sum(p)+sum(m) sum(p)+sum(m) ans_tmp def mylistinput(n):
    return [ list(myinput()) for _ in range(n) ] def mylistinput(n):
    return [ list(myinput()) for _ in range(n) ] mylistinput class Heapq:
    def __init__(self, arr, desc = False):
        if desc:
            for i in range(len(arr)):
                arr[i] = Reverse(arr[i])
        self.desc = desc
        self.hq = arr
        heapq.heapify(self.hq)
 
    def pop(self):
        if self.desc: return heapq.heappop(self.hq).val
        else: return heapq.heappop(self.hq)
 
    def push(self, a):
        if self.desc: heapq.heappush(self.hq, Reverse(a))
        else: heapq.heappush(self.hq, a)
 
    def top(self):
        if self.desc: self.hq[0].val
        else: return self.hq[0]
# ----- heapq ここまで----- class Heapq:
    def __init__(self, arr, desc = False):
        if desc:
            for i in range(len(arr)):
                arr[i] = Reverse(arr[i])
        self.desc = desc
        self.hq = arr
        heapq.heapify(self.hq)
 
    def pop(self):
        if self.desc: return heapq.heappop(self.hq).val
        else: return heapq.heappop(self.hq)
 
    def push(self, a):
        if self.desc: heapq.heappush(self.hq, Reverse(a))
        else: heapq.heappush(self.hq, a)
 
    def top(self):
        if self.desc: self.hq[0].val
        else: return self.hq[0]
# ----- heapq ここまで----- Heapq ans = max(ans,ans_tmp) max(ans,ans_tmp) ans def mysort(data,col,reverse_flag):
    data.sort(key=lambda x:x[col],reverse=reverse_flag)
    return data def mysort(data,col,reverse_flag):
    data.sort(key=lambda x:x[col],reverse=reverse_flag)
    return data mysort def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M mymax k = myinput() myinput() k p = [ i for i in have if i>=0 ] [ i for i in have if i>=0 ] p
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import permutations,combinations
from collections import defaultdict,Counter
from bisect import bisect_left,bisect_right
# from math import gcd,ceil,floor,factorial
# from fractions import gcd
from functools import reduce
from pprint import pprint

def myinput():
    return map(int,input().split())

def mylistinput(n):
    return [ list(myinput()) for _ in range(n) ]

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col,reverse_flag):
    data.sort(key=lambda x:x[col],reverse=reverse_flag)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(" ")
        elif type(ls[0])==str:
            print(" ".join(ls))
        elif type(ls[0])==int:
            print(" ".join(map(str,ls)))
        else:
            print("Output Error")
    else:
        if len(ls)==0:
            print("")
        elif type(ls[0])==str:
            print("".join(ls))
        elif type(ls[0])==int:
            print("".join(map(str,ls)))
        else:
            print("Output Error")

# ----- heapq ここから-----
import heapq
class Reverse:
    def __init__(self, val):
        self.val = val
        
    def __lt__(self, other):
        return self.val > other.val
        
    def __repr__(self):
        return repr(self.val)
    
class Heapq:
    def __init__(self, arr, desc = False):
        if desc:
            for i in range(len(arr)):
                arr[i] = Reverse(arr[i])
        self.desc = desc
        self.hq = arr
        heapq.heapify(self.hq)
 
    def pop(self):
        if self.desc: return heapq.heappop(self.hq).val
        else: return heapq.heappop(self.hq)
 
    def push(self, a):
        if self.desc: heapq.heappush(self.hq, Reverse(a))
        else: heapq.heappush(self.hq, a)
 
    def top(self):
        if self.desc: self.hq[0].val
        else: return self.hq[0]
# ----- heapq ここまで-----

n,k = myinput()
v = list(myinput())
vr = v[::-1]

ls = [-1,-1]
ans = -float("inf")
for a in range(k+1):
    for b in range(min(k-a+1,n-a+1)):
        have = []
        have.extend( v[:a] )
        have.extend( vr[:b] )
        p = [ i for i in have if i>=0 ]
        m = [ i for i in have if i<0 ]
        m.sort()
        r = k - a - b
        m = m[r:]
        ans_tmp = sum(p)+sum(m)
        if ans<ans_tmp:
            ls[0] = a
            ls[1] = b
        ans = max(ans,ans_tmp)
# print(ls)
print(ans)