#import math
#import itertools
#import numpy as np
from collections import deque


INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))

def do():
    n,k=INTM()
    d=LIST()
    #q=deque(d)
    nkmin=min(n,k)
    stop=10**9
    ans=0
    for i1 in range(1,1+nkmin):
        for i2 in range(i1+1):
            temp=d[0:i2]+d[n-(i1-i2):]
            #print(temp,i1,i2)
            temp=sorted(temp)
            #print(temp,i1,i2)
            for i3 in range(i1):
                if temp[i3]>=0 or i3>=k-i1:
                    stop=i3
                    break
                stop=10**9
            if stop!=10**9:
                #print(temp[i3:],1)
                ans=max(sum(temp[i3:]),ans)
    
    print(ans)



if __name__=='__main__':
    do() from collections import deque INT = lambda: int(input()) INT lambda: int(input()) int(input()) int input() input INTM = lambda: map(int,input().split()) INTM lambda: map(int,input().split()) map(int,input().split()) map int input().split() ().split () input split STRM = lambda: map(str,input().split()) STRM lambda: map(str,input().split()) map(str,input().split()) map str input().split() ().split () input split STR = lambda: str(input()) STR lambda: str(input()) str(input()) str input() input LIST = lambda: list(map(int,input().split())) LIST lambda: list(map(int,input().split())) list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split LISTS = lambda: list(map(str,input().split())) LISTS lambda: list(map(str,input().split())) list(map(str,input().split())) list map(str,input().split()) map str input().split() ().split () input split def do():
    n,k=INTM()
    d=LIST()
    #q=deque(d)
    nkmin=min(n,k)
    stop=10**9
    ans=0
    for i1 in range(1,1+nkmin):
        for i2 in range(i1+1):
            temp=d[0:i2]+d[n-(i1-i2):]
            #print(temp,i1,i2)
            temp=sorted(temp)
            #print(temp,i1,i2)
            for i3 in range(i1):
                if temp[i3]>=0 or i3>=k-i1:
                    stop=i3
                    break
                stop=10**9
            if stop!=10**9:
                #print(temp[i3:],1)
                ans=max(sum(temp[i3:]),ans)
    
    print(ans) do n,k=INTM() n INTM() INTM k d=LIST() d LIST() LIST nkmin=min(n,k) nkmin min(n,k) min n k stop=10**9 stop 10**9 10 9 ans=0 ans 0 for i1 in range(1,1+nkmin):
        for i2 in range(i1+1):
            temp=d[0:i2]+d[n-(i1-i2):]
            #print(temp,i1,i2)
            temp=sorted(temp)
            #print(temp,i1,i2)
            for i3 in range(i1):
                if temp[i3]>=0 or i3>=k-i1:
                    stop=i3
                    break
                stop=10**9
            if stop!=10**9:
                #print(temp[i3:],1)
                ans=max(sum(temp[i3:]),ans)
    
     i1 range(1,1+nkmin) range 1 1+nkmin 1 nkmin for i2 in range(i1+1):
            temp=d[0:i2]+d[n-(i1-i2):]
            #print(temp,i1,i2)
            temp=sorted(temp)
            #print(temp,i1,i2)
            for i3 in range(i1):
                if temp[i3]>=0 or i3>=k-i1:
                    stop=i3
                    break
                stop=10**9
            if stop!=10**9:
                #print(temp[i3:],1)
                ans=max(sum(temp[i3:]),ans)
    
     i2 range(i1+1) range i1+1 i1 1 temp=d[0:i2]+d[n-(i1-i2):] temp d[0:i2]+d[n-(i1-i2):] d[0:i2] d 0:i2 0 i2 d[n-(i1-i2):] d n-(i1-i2): n-(i1-i2) n i1-i2 i1 i2 temp=sorted(temp) temp sorted(temp) sorted temp for i3 in range(i1):
                if temp[i3]>=0 or i3>=k-i1:
                    stop=i3
                    break
                stop=10**9
             i3 range(i1) range i1 if temp[i3]>=0 or i3>=k-i1:
                    stop=i3
                    break
                 temp[i3]>=0 or i3>=k-i1 temp[i3]>=0 temp[i3] temp i3 0 i3>=k-i1 i3 k-i1 k i1 stop=i3 stop i3 break stop=10**9 stop 10**9 10 9 if stop!=10**9:
                #print(temp[i3:],1)
                ans=max(sum(temp[i3:]),ans)
    
     stop!=10**9 stop 10**9 10 9 ans=max(sum(temp[i3:]),ans) ans max(sum(temp[i3:]),ans) max sum(temp[i3:]) sum temp[i3:] temp i3: i3 ans print(ans) print ans if __name__=='__main__':
    do() __name__=='__main__' __name__ '__main__' do() do STRM = lambda: map(str,input().split()) lambda: map(str,input().split()) STRM LISTS = lambda: list(map(str,input().split())) lambda: list(map(str,input().split())) LISTS STR = lambda: str(input()) lambda: str(input()) STR INTM = lambda: map(int,input().split()) lambda: map(int,input().split()) INTM def do():
    n,k=INTM()
    d=LIST()
    #q=deque(d)
    nkmin=min(n,k)
    stop=10**9
    ans=0
    for i1 in range(1,1+nkmin):
        for i2 in range(i1+1):
            temp=d[0:i2]+d[n-(i1-i2):]
            #print(temp,i1,i2)
            temp=sorted(temp)
            #print(temp,i1,i2)
            for i3 in range(i1):
                if temp[i3]>=0 or i3>=k-i1:
                    stop=i3
                    break
                stop=10**9
            if stop!=10**9:
                #print(temp[i3:],1)
                ans=max(sum(temp[i3:]),ans)
    
    print(ans) def do():
    n,k=INTM()
    d=LIST()
    #q=deque(d)
    nkmin=min(n,k)
    stop=10**9
    ans=0
    for i1 in range(1,1+nkmin):
        for i2 in range(i1+1):
            temp=d[0:i2]+d[n-(i1-i2):]
            #print(temp,i1,i2)
            temp=sorted(temp)
            #print(temp,i1,i2)
            for i3 in range(i1):
                if temp[i3]>=0 or i3>=k-i1:
                    stop=i3
                    break
                stop=10**9
            if stop!=10**9:
                #print(temp[i3:],1)
                ans=max(sum(temp[i3:]),ans)
    
    print(ans) do LIST = lambda: list(map(int,input().split())) lambda: list(map(int,input().split())) LIST INT = lambda: int(input()) lambda: int(input()) INT
#import math
#import itertools
#import numpy as np
from collections import deque


INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))

def do():
    n,k=INTM()
    d=LIST()
    #q=deque(d)
    nkmin=min(n,k)
    stop=10**9
    ans=0
    for i1 in range(1,1+nkmin):
        for i2 in range(i1+1):
            temp=d[0:i2]+d[n-(i1-i2):]
            #print(temp,i1,i2)
            temp=sorted(temp)
            #print(temp,i1,i2)
            for i3 in range(i1):
                if temp[i3]>=0 or i3>=k-i1:
                    stop=i3
                    break
                stop=10**9
            if stop!=10**9:
                #print(temp[i3:],1)
                ans=max(sum(temp[i3:]),ans)
    
    print(ans)



if __name__=='__main__':
    do()