import sys
import collections
import itertools

sys.setrecursionlimit(10 ** 8)
ni = lambda: int(sys.stdin.readline())
nm = lambda: map(int, sys.stdin.readline().split())
nl = lambda: list(nm())
ns = lambda: sys.stdin.readline().rstrip()

N, K = nm()
V = nl()
assert len(V) == N
INF = 10 ** 9


def solve():
    ans = 0
    for i in range(K + 1):
        if i > N:
            break
        for j in range(K + 1 - i):
            if i + j > N:
                break
            v = V[:i] + V[N - j :]
            v.sort()
            s = sum(v)
            k = 0
            while k < K - i - j:
                if k >= len(v):
                    break
                if v[k] >= 0:
                    break
                s -= v[k]
                k += 1
            if ans < s:
                ans = s
                # print(f"> ans={ans} i={i}, j={j}, k={k}", file=sys.stderr)
    return ans


print(solve()) import sys sys import collections collections import itertools itertools sys.setrecursionlimit(10 ** 8) sys.setrecursionlimit sys setrecursionlimit 10 ** 8 10 8 ni = lambda: int(sys.stdin.readline()) ni lambda: int(sys.stdin.readline()) int(sys.stdin.readline()) int sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline nm = lambda: map(int, sys.stdin.readline().split()) nm lambda: map(int, sys.stdin.readline().split()) map(int, sys.stdin.readline().split()) map int sys.stdin.readline().split() sys.stdin.readline().split sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline split nl = lambda: list(nm()) nl lambda: list(nm()) list(nm()) list nm() nm ns = lambda: sys.stdin.readline().rstrip() ns lambda: sys.stdin.readline().rstrip() sys.stdin.readline().rstrip() sys.stdin.readline().rstrip sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline rstrip N, K = nm() N nm() nm K V = nl() V nl() nl assert len(V) == N len(V) == N len(V) len V N INF = 10 ** 9 INF 10 ** 9 10 9 def solve():
    ans = 0
    for i in range(K + 1):
        if i > N:
            break
        for j in range(K + 1 - i):
            if i + j > N:
                break
            v = V[:i] + V[N - j :]
            v.sort()
            s = sum(v)
            k = 0
            while k < K - i - j:
                if k >= len(v):
                    break
                if v[k] >= 0:
                    break
                s -= v[k]
                k += 1
            if ans < s:
                ans = s
                # print(f"> ans={ans} i={i}, j={j}, k={k}", file=sys.stderr)
    return ans solve ans = 0 ans 0 for i in range(K + 1):
        if i > N:
            break
        for j in range(K + 1 - i):
            if i + j > N:
                break
            v = V[:i] + V[N - j :]
            v.sort()
            s = sum(v)
            k = 0
            while k < K - i - j:
                if k >= len(v):
                    break
                if v[k] >= 0:
                    break
                s -= v[k]
                k += 1
            if ans < s:
                ans = s
                # print(f"> ans={ans} i={i}, j={j}, k={k}", file=sys.stderr)
     i range(K + 1) range K + 1 K 1 if i > N:
            break
         i > N i N break for j in range(K + 1 - i):
            if i + j > N:
                break
            v = V[:i] + V[N - j :]
            v.sort()
            s = sum(v)
            k = 0
            while k < K - i - j:
                if k >= len(v):
                    break
                if v[k] >= 0:
                    break
                s -= v[k]
                k += 1
            if ans < s:
                ans = s
                # print(f"> ans={ans} i={i}, j={j}, k={k}", file=sys.stderr)
     j range(K + 1 - i) range K + 1 - i K + 1 K 1 i if i + j > N:
                break
             i + j > N i + j i j N break v = V[:i] + V[N - j :] v V[:i] + V[N - j :] V[:i] V :i i V[N - j :] V N - j : N - j N j v.sort() v.sort v sort s = sum(v) s sum(v) sum v k = 0 k 0 while k < K - i - j:
                if k >= len(v):
                    break
                if v[k] >= 0:
                    break
                s -= v[k]
                k += 1
             k < K - i - j k K - i - j K - i K i j if k >= len(v):
                    break
                 k >= len(v) k len(v) len v break if v[k] >= 0:
                    break
                 v[k] >= 0 v[k] v k 0 break s -= v[k] s v[k] v k k += 1 k 1 if ans < s:
                ans = s
                # print(f"> ans={ans} i={i}, j={j}, k={k}", file=sys.stderr)
     ans < s ans s ans = s ans s return ans ans print(solve()) print solve() solve INF = 10 ** 9 10 ** 9 INF ns = lambda: sys.stdin.readline().rstrip() lambda: sys.stdin.readline().rstrip() ns N, K = nm() nm() N def solve():
    ans = 0
    for i in range(K + 1):
        if i > N:
            break
        for j in range(K + 1 - i):
            if i + j > N:
                break
            v = V[:i] + V[N - j :]
            v.sort()
            s = sum(v)
            k = 0
            while k < K - i - j:
                if k >= len(v):
                    break
                if v[k] >= 0:
                    break
                s -= v[k]
                k += 1
            if ans < s:
                ans = s
                # print(f"> ans={ans} i={i}, j={j}, k={k}", file=sys.stderr)
    return ans def solve():
    ans = 0
    for i in range(K + 1):
        if i > N:
            break
        for j in range(K + 1 - i):
            if i + j > N:
                break
            v = V[:i] + V[N - j :]
            v.sort()
            s = sum(v)
            k = 0
            while k < K - i - j:
                if k >= len(v):
                    break
                if v[k] >= 0:
                    break
                s -= v[k]
                k += 1
            if ans < s:
                ans = s
                # print(f"> ans={ans} i={i}, j={j}, k={k}", file=sys.stderr)
    return ans solve nm = lambda: map(int, sys.stdin.readline().split()) lambda: map(int, sys.stdin.readline().split()) nm V = nl() nl() V ni = lambda: int(sys.stdin.readline()) lambda: int(sys.stdin.readline()) ni nl = lambda: list(nm()) lambda: list(nm()) nl K = nm() nm() K
import sys
import collections
import itertools

sys.setrecursionlimit(10 ** 8)
ni = lambda: int(sys.stdin.readline())
nm = lambda: map(int, sys.stdin.readline().split())
nl = lambda: list(nm())
ns = lambda: sys.stdin.readline().rstrip()

N, K = nm()
V = nl()
assert len(V) == N
INF = 10 ** 9


def solve():
    ans = 0
    for i in range(K + 1):
        if i > N:
            break
        for j in range(K + 1 - i):
            if i + j > N:
                break
            v = V[:i] + V[N - j :]
            v.sort()
            s = sum(v)
            k = 0
            while k < K - i - j:
                if k >= len(v):
                    break
                if v[k] >= 0:
                    break
                s -= v[k]
                k += 1
            if ans < s:
                ans = s
                # print(f"> ans={ans} i={i}, j={j}, k={k}", file=sys.stderr)
    return ans


print(solve())
