import sys
from bisect import bisect_left


read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60


def main():
    N, K, *V = map(int, read().split())

    ans = 0
    for k in range(min(N, K) + 1):
        for left in range(k + 1):
            right = k - left
            tmp = V[:left] + (V[-right:] if right else [])
            tmp.sort()

            idx = bisect_left(tmp, 0)
            if idx > K - k:
                idx = K - k

            this_ans = sum(tmp[idx:])
            if ans < this_ans:
                ans = this_ans

    print(ans)
    return


if __name__ == '__main__':
    main() import sys sys from bisect import bisect_left read = sys.stdin.read read sys.stdin.read sys.stdin sys stdin read readline = sys.stdin.readline readline sys.stdin.readline sys.stdin sys stdin readline readlines = sys.stdin.readlines readlines sys.stdin.readlines sys.stdin sys stdin readlines sys.setrecursionlimit(10 ** 9) sys.setrecursionlimit sys setrecursionlimit 10 ** 9 10 9 INF = 1 << 60 INF 1 << 60 1 60 def main():
    N, K, *V = map(int, read().split())

    ans = 0
    for k in range(min(N, K) + 1):
        for left in range(k + 1):
            right = k - left
            tmp = V[:left] + (V[-right:] if right else [])
            tmp.sort()

            idx = bisect_left(tmp, 0)
            if idx > K - k:
                idx = K - k

            this_ans = sum(tmp[idx:])
            if ans < this_ans:
                ans = this_ans

    print(ans)
    return main N, K, *V = map(int, read().split()) N map(int, read().split()) map int read().split() ().split () read split K *V V ans = 0 ans 0 for k in range(min(N, K) + 1):
        for left in range(k + 1):
            right = k - left
            tmp = V[:left] + (V[-right:] if right else [])
            tmp.sort()

            idx = bisect_left(tmp, 0)
            if idx > K - k:
                idx = K - k

            this_ans = sum(tmp[idx:])
            if ans < this_ans:
                ans = this_ans

     k range(min(N, K) + 1) range min(N, K) + 1 min(N, K) min N K 1 for left in range(k + 1):
            right = k - left
            tmp = V[:left] + (V[-right:] if right else [])
            tmp.sort()

            idx = bisect_left(tmp, 0)
            if idx > K - k:
                idx = K - k

            this_ans = sum(tmp[idx:])
            if ans < this_ans:
                ans = this_ans

     left range(k + 1) range k + 1 k 1 right = k - left right k - left k left tmp = V[:left] + (V[-right:] if right else []) tmp V[:left] + (V[-right:] if right else []) V[:left] V :left left V[-right:] if right else [] right V[-right:] V -right: -right right [] tmp.sort() tmp.sort tmp sort idx = bisect_left(tmp, 0) idx bisect_left(tmp, 0) bisect_left tmp 0 if idx > K - k:
                idx = K - k

             idx > K - k idx K - k K k idx = K - k idx K - k K k this_ans = sum(tmp[idx:]) this_ans sum(tmp[idx:]) sum tmp[idx:] tmp idx: idx if ans < this_ans:
                ans = this_ans

     ans < this_ans ans this_ans ans = this_ans ans this_ans print(ans) print ans return if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main def main():
    N, K, *V = map(int, read().split())

    ans = 0
    for k in range(min(N, K) + 1):
        for left in range(k + 1):
            right = k - left
            tmp = V[:left] + (V[-right:] if right else [])
            tmp.sort()

            idx = bisect_left(tmp, 0)
            if idx > K - k:
                idx = K - k

            this_ans = sum(tmp[idx:])
            if ans < this_ans:
                ans = this_ans

    print(ans)
    return def main():
    N, K, *V = map(int, read().split())

    ans = 0
    for k in range(min(N, K) + 1):
        for left in range(k + 1):
            right = k - left
            tmp = V[:left] + (V[-right:] if right else [])
            tmp.sort()

            idx = bisect_left(tmp, 0)
            if idx > K - k:
                idx = K - k

            this_ans = sum(tmp[idx:])
            if ans < this_ans:
                ans = this_ans

    print(ans)
    return main read = sys.stdin.read sys.stdin.read read readlines = sys.stdin.readlines sys.stdin.readlines readlines readline = sys.stdin.readline sys.stdin.readline readline INF = 1 << 60 1 << 60 INF
import sys
from bisect import bisect_left


read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60


def main():
    N, K, *V = map(int, read().split())

    ans = 0
    for k in range(min(N, K) + 1):
        for left in range(k + 1):
            right = k - left
            tmp = V[:left] + (V[-right:] if right else [])
            tmp.sort()

            idx = bisect_left(tmp, 0)
            if idx > K - k:
                idx = K - k

            this_ans = sum(tmp[idx:])
            if ans < this_ans:
                ans = this_ans

    print(ans)
    return


if __name__ == '__main__':
    main()
