# solution

def solve(string):
    n, k, *v = map(int, string.split())
    ans = 0
    for i in range(k + 1):
        for j in range(k - i + 1):
            base = sorted(v[:i] + v[max(n - k + i + j, i):])
            ans = max(ans, sum([b for l, b in enumerate(base) if b >= 0 or j <= l]))
    return str(ans)


if __name__ == '__main__':
    print(solve('\n'.join([input(), input()]))) def solve(string):
    n, k, *v = map(int, string.split())
    ans = 0
    for i in range(k + 1):
        for j in range(k - i + 1):
            base = sorted(v[:i] + v[max(n - k + i + j, i):])
            ans = max(ans, sum([b for l, b in enumerate(base) if b >= 0 or j <= l]))
    return str(ans) solve n, k, *v = map(int, string.split()) n map(int, string.split()) map int string.split() string.split string split k *v v ans = 0 ans 0 for i in range(k + 1):
        for j in range(k - i + 1):
            base = sorted(v[:i] + v[max(n - k + i + j, i):])
            ans = max(ans, sum([b for l, b in enumerate(base) if b >= 0 or j <= l]))
     i range(k + 1) range k + 1 k 1 for j in range(k - i + 1):
            base = sorted(v[:i] + v[max(n - k + i + j, i):])
            ans = max(ans, sum([b for l, b in enumerate(base) if b >= 0 or j <= l]))
     j range(k - i + 1) range k - i + 1 k - i k i 1 base = sorted(v[:i] + v[max(n - k + i + j, i):]) base sorted(v[:i] + v[max(n - k + i + j, i):]) sorted v[:i] + v[max(n - k + i + j, i):] v[:i] v :i i v[max(n - k + i + j, i):] v max(n - k + i + j, i): max(n - k + i + j, i) max n - k + i + j n - k + i n - k n k i j i b for l, b in enumerate(base) if b >= 0 or j <= l for l, b in enumerate(base) if b >= 0 or j <= l l b enumerate(base) enumerate base b >= 0 or j <= l b >= 0 b 0 j <= l j l if b >= 0 or j <= l b ans = max(ans, sum([b for l, b in enumerate(base) if b >= 0 or j <= l])) ans max(ans, sum([b for l, b in enumerate(base) if b >= 0 or j <= l])) max ans sum([b for l, b in enumerate(base) if b >= 0 or j <= l]) sum [b for l, b in enumerate(base) if b >= 0 or j <= l] return str(ans) str(ans) str ans string string if __name__ == '__main__':
    print(solve('\n'.join([input(), input()]))) __name__ == '__main__' __name__ '__main__' print(solve('\n'.join([input(), input()]))) print solve('\n'.join([input(), input()])) solve '\n'.join([input(), input()]) '\n'.join '\n' join [input(), input()] input() input input() input def solve(string):
    n, k, *v = map(int, string.split())
    ans = 0
    for i in range(k + 1):
        for j in range(k - i + 1):
            base = sorted(v[:i] + v[max(n - k + i + j, i):])
            ans = max(ans, sum([b for l, b in enumerate(base) if b >= 0 or j <= l]))
    return str(ans) def solve(string):
    n, k, *v = map(int, string.split())
    ans = 0
    for i in range(k + 1):
        for j in range(k - i + 1):
            base = sorted(v[:i] + v[max(n - k + i + j, i):])
            ans = max(ans, sum([b for l, b in enumerate(base) if b >= 0 or j <= l]))
    return str(ans) solve
# solution

def solve(string):
    n, k, *v = map(int, string.split())
    ans = 0
    for i in range(k + 1):
        for j in range(k - i + 1):
            base = sorted(v[:i] + v[max(n - k + i + j, i):])
            ans = max(ans, sum([b for l, b in enumerate(base) if b >= 0 or j <= l]))
    return str(ans)


if __name__ == '__main__':
    print(solve('\n'.join([input(), input()])))
