from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    n, k = map(int, input().split())
    v = list(map(int, input().split()))

    max = 0

    for i in range(k):
        if i <= n:
            for j in range(i + 1):
                candidate = v[0:j + 1]
                candidate.extend(v[n - i + j:n])
                candidate.sort()
                for d in range(k - i):
                    tmp = sum(candidate[d:n])
                    if tmp > max:
                        max = tmp
        else:
            candidate = v
            candidate.sort()
            for d in range(k - i):
                tmp = sum(candidate[d:n])
                if tmp > max:
                    max = tmp
    print(max)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main() from sys import stdin, setrecursionlimit def main():
    input = stdin.buffer.readline
    n, k = map(int, input().split())
    v = list(map(int, input().split()))

    max = 0

    for i in range(k):
        if i <= n:
            for j in range(i + 1):
                candidate = v[0:j + 1]
                candidate.extend(v[n - i + j:n])
                candidate.sort()
                for d in range(k - i):
                    tmp = sum(candidate[d:n])
                    if tmp > max:
                        max = tmp
        else:
            candidate = v
            candidate.sort()
            for d in range(k - i):
                tmp = sum(candidate[d:n])
                if tmp > max:
                    max = tmp
    print(max) main input = stdin.buffer.readline input stdin.buffer.readline stdin.buffer stdin buffer readline n, k = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split k v = list(map(int, input().split())) v list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split max = 0 max 0 for i in range(k):
        if i <= n:
            for j in range(i + 1):
                candidate = v[0:j + 1]
                candidate.extend(v[n - i + j:n])
                candidate.sort()
                for d in range(k - i):
                    tmp = sum(candidate[d:n])
                    if tmp > max:
                        max = tmp
        else:
            candidate = v
            candidate.sort()
            for d in range(k - i):
                tmp = sum(candidate[d:n])
                if tmp > max:
                    max = tmp
     i range(k) range k if i <= n:
            for j in range(i + 1):
                candidate = v[0:j + 1]
                candidate.extend(v[n - i + j:n])
                candidate.sort()
                for d in range(k - i):
                    tmp = sum(candidate[d:n])
                    if tmp > max:
                        max = tmp
        else:
            candidate = v
            candidate.sort()
            for d in range(k - i):
                tmp = sum(candidate[d:n])
                if tmp > max:
                    max = tmp
     i <= n i n for j in range(i + 1):
                candidate = v[0:j + 1]
                candidate.extend(v[n - i + j:n])
                candidate.sort()
                for d in range(k - i):
                    tmp = sum(candidate[d:n])
                    if tmp > max:
                        max = tmp
         j range(i + 1) range i + 1 i 1 candidate = v[0:j + 1] candidate v[0:j + 1] v 0:j + 1 0 j + 1 j 1 candidate.extend(v[n - i + j:n]) candidate.extend candidate extend v[n - i + j:n] v n - i + j:n n - i + j n - i n i j n candidate.sort() candidate.sort candidate sort for d in range(k - i):
                    tmp = sum(candidate[d:n])
                    if tmp > max:
                        max = tmp
         d range(k - i) range k - i k i tmp = sum(candidate[d:n]) tmp sum(candidate[d:n]) sum candidate[d:n] candidate d:n d n if tmp > max:
                        max = tmp
         tmp > max tmp max max = tmp max tmp candidate = v candidate v candidate.sort() candidate.sort candidate sort for d in range(k - i):
                tmp = sum(candidate[d:n])
                if tmp > max:
                    max = tmp
     d range(k - i) range k - i k i tmp = sum(candidate[d:n]) tmp sum(candidate[d:n]) sum candidate[d:n] candidate d:n d n if tmp > max:
                    max = tmp
     tmp > max tmp max max = tmp max tmp print(max) print max if __name__ == "__main__":
    setrecursionlimit(10000)
    main() __name__ == "__main__" __name__ "__main__" setrecursionlimit(10000) setrecursionlimit 10000 main() main def main():
    input = stdin.buffer.readline
    n, k = map(int, input().split())
    v = list(map(int, input().split()))

    max = 0

    for i in range(k):
        if i <= n:
            for j in range(i + 1):
                candidate = v[0:j + 1]
                candidate.extend(v[n - i + j:n])
                candidate.sort()
                for d in range(k - i):
                    tmp = sum(candidate[d:n])
                    if tmp > max:
                        max = tmp
        else:
            candidate = v
            candidate.sort()
            for d in range(k - i):
                tmp = sum(candidate[d:n])
                if tmp > max:
                    max = tmp
    print(max) def main():
    input = stdin.buffer.readline
    n, k = map(int, input().split())
    v = list(map(int, input().split()))

    max = 0

    for i in range(k):
        if i <= n:
            for j in range(i + 1):
                candidate = v[0:j + 1]
                candidate.extend(v[n - i + j:n])
                candidate.sort()
                for d in range(k - i):
                    tmp = sum(candidate[d:n])
                    if tmp > max:
                        max = tmp
        else:
            candidate = v
            candidate.sort()
            for d in range(k - i):
                tmp = sum(candidate[d:n])
                if tmp > max:
                    max = tmp
    print(max) main
from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    n, k = map(int, input().split())
    v = list(map(int, input().split()))

    max = 0

    for i in range(k):
        if i <= n:
            for j in range(i + 1):
                candidate = v[0:j + 1]
                candidate.extend(v[n - i + j:n])
                candidate.sort()
                for d in range(k - i):
                    tmp = sum(candidate[d:n])
                    if tmp > max:
                        max = tmp
        else:
            candidate = v
            candidate.sort()
            for d in range(k - i):
                tmp = sum(candidate[d:n])
                if tmp > max:
                    max = tmp
    print(max)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()
