n, k = list(map(int, input().split()))

v = list(map(int, input().split()))



# 左から何個、右から何個を全探索

ans = 0

for l in range(0, k + 1):

    for r in range(0, k + 1 - l):

        if l + r > n:

            continue

        suteru = k - l - r

        get = []

        for i in range(l):

            get.append(v[i])

        for i in range(n - 1, n - 1 - r, -1):

            get.append(v[i])

        get.sort()

        minus = 0

        while minus < min(suteru, len(get)) and get[minus] < 0:

            minus += 1

        ans = max(ans, sum(get[minus:]))

print(ans)

n, k = list(map(int, input().split()))

v = list(map(int, input().split()))



ans = 0

for l in range(0, k + 1):

    for r in range(0, k + 1 - l):

        if l == r == 0 or l + r > n:

            continue

        a = sorted(v[:l] + v[n - r:])

        m = min(k - l - r, len(a) - 1)

        ans = max(ans, sum(a[m:] if a[m] <

                           0 else [x for x in a if x > 0]))

print(ans)
n, k = list(map(int, input().split()))
v = list(map(int, input().split()))
# 左から何個、右から何個を全探索
ans = 0
for l in range(0, k + 1):
    for r in range(0, k + 1 - l):
        if l + r > n:
            continue
        suteru = k - l - r
        get = []
        for i in range(l):
            get.append(v[i])
        for i in range(n - 1, n - 1 - r, -1):
            get.append(v[i])
        get.sort()
        minus = 0
        while minus < min(suteru, len(get)) and get[minus] < 0:
            minus += 1
        ans = max(ans, sum(get[minus:]))
print(ans)

n, k = list(map(int, input().split()))
v = list(map(int, input().split()))
ans = 0
for l in range(0, k + 1):
    for r in range(0, k + 1 - l):
        if l == r == 0 or l + r > n:
            continue
        a = sorted(v[:l] + v[n - r :])
        m = min(k - l - r, len(a) - 1)
        ans = max(ans, sum(a[m:] if a[m] < 0 else [x for x in a if x > 0]))
print(ans)

-# 左から何個、右から何個を全探索 -        if l + r > n: +        if l == r == 0 or l + r > n: -        suteru = k - l - r -        get = [] -        for i in range(l): -            get.append(v[i]) -        for i in range(n - 1, n - 1 - r, -1): -            get.append(v[i]) -        get.sort() -        minus = 0 -        while minus < min(suteru, len(get)) and get[minus] < 0: -            minus += 1 -        ans = max(ans, sum(get[minus:])) +        a = sorted(v[:l] + v[n - r :]) +        m = min(k - l - r, len(a) - 1) +        ans = max(ans, sum(a[m:] if a[m] < 0 else [x for x in a if x > 0]))