# 解説を参考に作成
# import sys
# sys.setrecursionlimit(10 ** 6)
# import bisect
from collections import deque
import heapq


# from decorator import stop_watch
#
#
# @stop_watch
def solve(N, K, Vi):
    ans = 0
    for ab in range(min(N, K) + 1):
        for a in range(ab + 1):
            b = ab - a
            have = Vi[:a] + Vi[N - b:]
            have.sort()
            s = sum(have)
            for i in range(K - ab):
                if len(have) <= i:
                    break
                elif have[i] < 0:
                    s += abs(have[i])
                else:
                    break
            ans = max(ans, s)
    print(ans)


if __name__ == '__main__':
    N, K = map(int, input().split())
    Vi = [int(i) for i in input().split()]
    solve(N, K, Vi)

    # # test
    # import random
    # from func import random_str
    # N, K = 100, 50
    # Vi = [random.randint(-(10 ** 7), 10 ** 7) for _ in range(N)]
    # solve(N, K, Vi) from collections import deque import heapq heapq def solve(N, K, Vi):
    ans = 0
    for ab in range(min(N, K) + 1):
        for a in range(ab + 1):
            b = ab - a
            have = Vi[:a] + Vi[N - b:]
            have.sort()
            s = sum(have)
            for i in range(K - ab):
                if len(have) <= i:
                    break
                elif have[i] < 0:
                    s += abs(have[i])
                else:
                    break
            ans = max(ans, s)
    print(ans) solve ans = 0 ans 0 for ab in range(min(N, K) + 1):
        for a in range(ab + 1):
            b = ab - a
            have = Vi[:a] + Vi[N - b:]
            have.sort()
            s = sum(have)
            for i in range(K - ab):
                if len(have) <= i:
                    break
                elif have[i] < 0:
                    s += abs(have[i])
                else:
                    break
            ans = max(ans, s)
     ab range(min(N, K) + 1) range min(N, K) + 1 min(N, K) min N K 1 for a in range(ab + 1):
            b = ab - a
            have = Vi[:a] + Vi[N - b:]
            have.sort()
            s = sum(have)
            for i in range(K - ab):
                if len(have) <= i:
                    break
                elif have[i] < 0:
                    s += abs(have[i])
                else:
                    break
            ans = max(ans, s)
     a range(ab + 1) range ab + 1 ab 1 b = ab - a b ab - a ab a have = Vi[:a] + Vi[N - b:] have Vi[:a] + Vi[N - b:] Vi[:a] Vi :a a Vi[N - b:] Vi N - b: N - b N b have.sort() have.sort have sort s = sum(have) s sum(have) sum have for i in range(K - ab):
                if len(have) <= i:
                    break
                elif have[i] < 0:
                    s += abs(have[i])
                else:
                    break
             i range(K - ab) range K - ab K ab if len(have) <= i:
                    break
                elif have[i] < 0:
                    s += abs(have[i])
                else:
                    break
             len(have) <= i len(have) len have i break elif have[i] < 0:
                    s += abs(have[i])
                 have[i] < 0 have[i] have i 0 s += abs(have[i]) s abs(have[i]) abs have[i] have i break ans = max(ans, s) ans max(ans, s) max ans s print(ans) print ans N N K K Vi Vi if __name__ == '__main__':
    N, K = map(int, input().split())
    Vi = [int(i) for i in input().split()]
    solve(N, K, Vi)

    # # test
    # import random
    # from func import random_str
    # N, K = 100, 50
    # Vi = [random.randint(-(10 ** 7), 10 ** 7) for _ in range(N)]
    # solve(N, K, Vi) __name__ == '__main__' __name__ '__main__' 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 Vi = [int(i) for i in input().split()] Vi [int(i) for i in input().split()] solve(N, K, Vi) solve N K Vi Vi = [int(i) for i in input().split()] [int(i) for i in input().split()] Vi N, K = map(int, input().split()) map(int, input().split()) N K = map(int, input().split()) map(int, input().split()) K def solve(N, K, Vi):
    ans = 0
    for ab in range(min(N, K) + 1):
        for a in range(ab + 1):
            b = ab - a
            have = Vi[:a] + Vi[N - b:]
            have.sort()
            s = sum(have)
            for i in range(K - ab):
                if len(have) <= i:
                    break
                elif have[i] < 0:
                    s += abs(have[i])
                else:
                    break
            ans = max(ans, s)
    print(ans) def solve(N, K, Vi):
    ans = 0
    for ab in range(min(N, K) + 1):
        for a in range(ab + 1):
            b = ab - a
            have = Vi[:a] + Vi[N - b:]
            have.sort()
            s = sum(have)
            for i in range(K - ab):
                if len(have) <= i:
                    break
                elif have[i] < 0:
                    s += abs(have[i])
                else:
                    break
            ans = max(ans, s)
    print(ans) solve
# 解説を参考に作成
# import sys
# sys.setrecursionlimit(10 ** 6)
# import bisect
from collections import deque
import heapq


# from decorator import stop_watch
#
#
# @stop_watch
def solve(N, K, Vi):
    ans = 0
    for ab in range(min(N, K) + 1):
        for a in range(ab + 1):
            b = ab - a
            have = Vi[:a] + Vi[N - b:]
            have.sort()
            s = sum(have)
            for i in range(K - ab):
                if len(have) <= i:
                    break
                elif have[i] < 0:
                    s += abs(have[i])
                else:
                    break
            ans = max(ans, s)
    print(ans)


if __name__ == '__main__':
    N, K = map(int, input().split())
    Vi = [int(i) for i in input().split()]
    solve(N, K, Vi)

    # # test
    # import random
    # from func import random_str
    # N, K = 100, 50
    # Vi = [random.randint(-(10 ** 7), 10 ** 7) for _ in range(N)]
    # solve(N, K, Vi)
