import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N,K,*V = map(int,read().split())

vals = []
for L in range(N+1):
    for R in range(N+1):
        if L+R > N:
            break
        get = V[:L] + V[N-R:]
        rest = K - (L+R)
        if rest < 0:
            break
        get.sort(reverse=True)
        for _ in range(min(len(get),rest)):
            if get[-1] < 0:
                get.pop()
            else:
                break
        vals.append(sum(get))

answer = max(vals)
print(answer) import sys sys read = sys.stdin.buffer.read read sys.stdin.buffer.read sys.stdin.buffer sys.stdin sys stdin buffer read readline = sys.stdin.buffer.readline readline sys.stdin.buffer.readline sys.stdin.buffer sys.stdin sys stdin buffer readline readlines = sys.stdin.buffer.readlines readlines sys.stdin.buffer.readlines sys.stdin.buffer sys.stdin sys stdin buffer readlines N,K,*V = map(int,read().split()) N map(int,read().split()) map int read().split() ().split () read split K *V V vals = [] vals [] for L in range(N+1):
    for R in range(N+1):
        if L+R > N:
            break
        get = V[:L] + V[N-R:]
        rest = K - (L+R)
        if rest < 0:
            break
        get.sort(reverse=True)
        for _ in range(min(len(get),rest)):
            if get[-1] < 0:
                get.pop()
            else:
                break
        vals.append(sum(get)) L range(N+1) range N+1 N 1 for R in range(N+1):
        if L+R > N:
            break
        get = V[:L] + V[N-R:]
        rest = K - (L+R)
        if rest < 0:
            break
        get.sort(reverse=True)
        for _ in range(min(len(get),rest)):
            if get[-1] < 0:
                get.pop()
            else:
                break
        vals.append(sum(get)) R range(N+1) range N+1 N 1 if L+R > N:
            break
         L+R > N L+R L R N break get = V[:L] + V[N-R:] get V[:L] + V[N-R:] V[:L] V :L L V[N-R:] V N-R: N-R N R rest = K - (L+R) rest K - (L+R) K L+R L R if rest < 0:
            break
         rest < 0 rest 0 break get.sort(reverse=True) get.sort get sort reverse=True reverse True for _ in range(min(len(get),rest)):
            if get[-1] < 0:
                get.pop()
            else:
                break
         _ range(min(len(get),rest)) range min(len(get),rest) min len(get) len get rest if get[-1] < 0:
                get.pop()
            else:
                break
         get[-1] < 0 get[-1] get -1 0 get.pop() get.pop get pop break vals.append(sum(get)) vals.append vals append sum(get) sum get answer = max(vals) answer max(vals) max vals print(answer) print answer read = sys.stdin.buffer.read sys.stdin.buffer.read read readline = sys.stdin.buffer.readline sys.stdin.buffer.readline readline N,K,*V = map(int,read().split()) map(int,read().split()) N K,*V = map(int,read().split()) map(int,read().split()) K get = V[:L] + V[N-R:] V[:L] + V[N-R:] get rest = K - (L+R) K - (L+R) rest answer = max(vals) max(vals) answer readlines = sys.stdin.buffer.readlines sys.stdin.buffer.readlines readlines vals = [] [] vals
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N,K,*V = map(int,read().split())

vals = []
for L in range(N+1):
    for R in range(N+1):
        if L+R > N:
            break
        get = V[:L] + V[N-R:]
        rest = K - (L+R)
        if rest < 0:
            break
        get.sort(reverse=True)
        for _ in range(min(len(get),rest)):
            if get[-1] < 0:
                get.pop()
            else:
                break
        vals.append(sum(get))

answer = max(vals)
print(answer)
