n, k = map(int, input().split())
vs = [int(i) for i in input().split()]


def getv(takel, taker, drop):
    g = vs[:takel] + vs[len(vs) - taker:] + [0] * drop
    return sum(sorted(g, reverse=True)[:takel + taker])


def getm(take):
    if take >= n:
        return getv(n, 0, k - take)
    else:
        m = 0
        for takel in range(take + 1):
            m = max([m, getv(takel, take - takel, k - take)])
        return m


def solve():
    return max([getm(take) for take in range(k + 1)])


print(solve()) n, k = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split k int(i) for i in input().split() for i in input().split() i input().split() ().split () input split for i in input().split() int(i) int i vs = [int(i) for i in input().split()] vs [int(i) for i in input().split()] def getv(takel, taker, drop):
    g = vs[:takel] + vs[len(vs) - taker:] + [0] * drop
    return sum(sorted(g, reverse=True)[:takel + taker]) getv g = vs[:takel] + vs[len(vs) - taker:] + [0] * drop g vs[:takel] + vs[len(vs) - taker:] + [0] * drop vs[:takel] + vs[len(vs) - taker:] vs[:takel] vs :takel takel vs[len(vs) - taker:] vs len(vs) - taker: len(vs) - taker len(vs) len vs taker [0] * drop [0] 0 drop return sum(sorted(g, reverse=True)[:takel + taker]) sum(sorted(g, reverse=True)[:takel + taker]) sum sorted(g, reverse=True)[:takel + taker] (g, reverse=True) sorted g reverse=True reverse True :takel + taker takel + taker takel taker takel takel taker taker drop drop def getm(take):
    if take >= n:
        return getv(n, 0, k - take)
    else:
        m = 0
        for takel in range(take + 1):
            m = max([m, getv(takel, take - takel, k - take)])
        return m getm if take >= n:
        return getv(n, 0, k - take)
    else:
        m = 0
        for takel in range(take + 1):
            m = max([m, getv(takel, take - takel, k - take)])
        return m take >= n take n return getv(n, 0, k - take) getv(n, 0, k - take) getv n 0 k - take k take m = 0 m 0 for takel in range(take + 1):
            m = max([m, getv(takel, take - takel, k - take)])
         takel range(take + 1) range take + 1 take 1 m = max([m, getv(takel, take - takel, k - take)]) m max([m, getv(takel, take - takel, k - take)]) max [m, getv(takel, take - takel, k - take)] m getv(takel, take - takel, k - take) getv takel take - takel take takel k - take k take return m m take take def solve():
    return max([getm(take) for take in range(k + 1)]) solve getm(take) for take in range(k + 1) for take in range(k + 1) take range(k + 1) range k + 1 k 1 for take in range(k + 1) getm(take) getm take return max([getm(take) for take in range(k + 1)]) max([getm(take) for take in range(k + 1)]) max [getm(take) for take in range(k + 1)] print(solve()) print solve() solve def getm(take):
    if take >= n:
        return getv(n, 0, k - take)
    else:
        m = 0
        for takel in range(take + 1):
            m = max([m, getv(takel, take - takel, k - take)])
        return m def getm(take):
    if take >= n:
        return getv(n, 0, k - take)
    else:
        m = 0
        for takel in range(take + 1):
            m = max([m, getv(takel, take - takel, k - take)])
        return m getm n, k = map(int, input().split()) map(int, input().split()) n def solve():
    return max([getm(take) for take in range(k + 1)]) def solve():
    return max([getm(take) for take in range(k + 1)]) solve vs = [int(i) for i in input().split()] [int(i) for i in input().split()] vs def getv(takel, taker, drop):
    g = vs[:takel] + vs[len(vs) - taker:] + [0] * drop
    return sum(sorted(g, reverse=True)[:takel + taker]) def getv(takel, taker, drop):
    g = vs[:takel] + vs[len(vs) - taker:] + [0] * drop
    return sum(sorted(g, reverse=True)[:takel + taker]) getv k = map(int, input().split()) map(int, input().split()) k
n, k = map(int, input().split())
vs = [int(i) for i in input().split()]


def getv(takel, taker, drop):
    g = vs[:takel] + vs[len(vs) - taker:] + [0] * drop
    return sum(sorted(g, reverse=True)[:takel + taker])


def getm(take):
    if take >= n:
        return getv(n, 0, k - take)
    else:
        m = 0
        for takel in range(take + 1):
            m = max([m, getv(takel, take - takel, k - take)])
        return m


def solve():
    return max([getm(take) for take in range(k + 1)])


print(solve())
