#!usr/bin/env python3
from collections import defaultdict, deque, Counter, OrderedDict
from bisect import bisect_left, bisect_right
from functools import reduce, lru_cache
from heapq import heappush, heappop, heapify

import itertools, bisect
import math, fractions
import sys, copy

def L(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline().rstrip())
def SL(): return list(sys.stdin.readline().rstrip())
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI1(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return [list(x) for x in sys.stdin.readline().split()]
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def LIR1(n): return [LI1() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
def LR(n): return [L() for _ in range(n)]

def perm(n, r): return math.factorial(n) // math.factorial(r)
def comb(n, r): return math.factorial(n) // (math.factorial(r) * math.factorial(n-r))

alphabets = "abcdefghijklmnopqrstuvwxyz"
ALPHABETS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

sys.setrecursionlimit(1000000)
dire = [[1, 0], [0, 1], [-1, 0], [0, -1]]
dire8 = [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]]
MOD = 1000000007
INF = float("inf")

def main():
    N, K = LI()
    V = LI()
    V2 = V + V

    ans = 0
    for k in range(1, min(K + 1, N + 1)):
        for i in range(len(V) - k, len(V) + 1):
            neg = []
            tmp = 0
            for vi in V2[i:i + k]:
                if vi < 0:
                    neg.append(vi)
                tmp += vi
            tmp -= sum(sorted(neg)[:K - k])
            ans = max(ans, tmp)

    print(ans)

if __name__ == '__main__':
    main() from collections import defaultdict, deque, Counter, OrderedDict from bisect import bisect_left, bisect_right from functools import reduce, lru_cache from heapq import heappush, heappop, heapify import itertools, bisect itertools bisect import math, fractions math fractions import sys, copy sys copy def L(): return sys.stdin.readline().split() L def I(): return int(sys.stdin.readline().rstrip()) I def SL(): return list(sys.stdin.readline().rstrip()) SL int(x) for x in sys.stdin.readline().split() for x in sys.stdin.readline().split() x sys.stdin.readline().split() sys.stdin.readline().split sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline split for x in sys.stdin.readline().split() int(x) int x def LI(): return [int(x) for x in sys.stdin.readline().split()] LI int(x) - 1 for x in sys.stdin.readline().split() for x in sys.stdin.readline().split() x sys.stdin.readline().split() sys.stdin.readline().split sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline split for x in sys.stdin.readline().split() int(x) - 1 int(x) int x 1 def LI1(): return [int(x) - 1 for x in sys.stdin.readline().split()] LI1 list(x) for x in sys.stdin.readline().split() for x in sys.stdin.readline().split() x sys.stdin.readline().split() sys.stdin.readline().split sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline split for x in sys.stdin.readline().split() list(x) list x def LS(): return [list(x) for x in sys.stdin.readline().split()] LS I() for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) I() I def IR(n): return [I() for _ in range(n)] IR n n LI() for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) LI() LI def LIR(n): return [LI() for _ in range(n)] LIR n n LI1() for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) LI1() LI1 def LIR1(n): return [LI1() for _ in range(n)] LIR1 n n S() for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) S() S def SR(n): return [S() for _ in range(n)] SR n n LS() for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) LS() LS def LSR(n): return [LS() for _ in range(n)] LSR n n L() for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) L() L def LR(n): return [L() for _ in range(n)] LR n n def perm(n, r): return math.factorial(n) // math.factorial(r) perm n n r r def comb(n, r): return math.factorial(n) // (math.factorial(r) * math.factorial(n-r)) comb n n r r alphabets = "abcdefghijklmnopqrstuvwxyz" alphabets "abcdefghijklmnopqrstuvwxyz" ALPHABETS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" ALPHABETS "ABCDEFGHIJKLMNOPQRSTUVWXYZ" sys.setrecursionlimit(1000000) sys.setrecursionlimit sys setrecursionlimit 1000000 dire = [[1, 0], [0, 1], [-1, 0], [0, -1]] dire [[1, 0], [0, 1], [-1, 0], [0, -1]] [1, 0] 1 0 [0, 1] 0 1 [-1, 0] -1 0 [0, -1] 0 -1 dire8 = [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]] dire8 [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]] [1, 0] 1 0 [1, 1] 1 1 [0, 1] 0 1 [-1, 1] -1 1 [-1, 0] -1 0 [-1, -1] -1 -1 [0, -1] 0 -1 [1, -1] 1 -1 MOD = 1000000007 MOD 1000000007 INF = float("inf") INF float("inf") float "inf" def main():
    N, K = LI()
    V = LI()
    V2 = V + V

    ans = 0
    for k in range(1, min(K + 1, N + 1)):
        for i in range(len(V) - k, len(V) + 1):
            neg = []
            tmp = 0
            for vi in V2[i:i + k]:
                if vi < 0:
                    neg.append(vi)
                tmp += vi
            tmp -= sum(sorted(neg)[:K - k])
            ans = max(ans, tmp)

    print(ans) main N, K = LI() N LI() LI K V = LI() V LI() LI V2 = V + V V2 V + V V V ans = 0 ans 0 for k in range(1, min(K + 1, N + 1)):
        for i in range(len(V) - k, len(V) + 1):
            neg = []
            tmp = 0
            for vi in V2[i:i + k]:
                if vi < 0:
                    neg.append(vi)
                tmp += vi
            tmp -= sum(sorted(neg)[:K - k])
            ans = max(ans, tmp)

     k range(1, min(K + 1, N + 1)) range 1 min(K + 1, N + 1) min K + 1 K 1 N + 1 N 1 for i in range(len(V) - k, len(V) + 1):
            neg = []
            tmp = 0
            for vi in V2[i:i + k]:
                if vi < 0:
                    neg.append(vi)
                tmp += vi
            tmp -= sum(sorted(neg)[:K - k])
            ans = max(ans, tmp)

     i range(len(V) - k, len(V) + 1) range len(V) - k len(V) len V k len(V) + 1 len(V) len V 1 neg = [] neg [] tmp = 0 tmp 0 for vi in V2[i:i + k]:
                if vi < 0:
                    neg.append(vi)
                tmp += vi
             vi V2[i:i + k] V2 i:i + k i i + k i k if vi < 0:
                    neg.append(vi)
                 vi < 0 vi 0 neg.append(vi) neg.append neg append vi tmp += vi tmp vi tmp -= sum(sorted(neg)[:K - k]) tmp sum(sorted(neg)[:K - k]) sum sorted(neg)[:K - k] (neg) sorted neg :K - k K - k K k ans = max(ans, tmp) ans max(ans, tmp) max ans tmp print(ans) print ans if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main def LSR(n): return [LS() for _ in range(n)] def LSR(n): return [LS() for _ in range(n)] LSR def main():
    N, K = LI()
    V = LI()
    V2 = V + V

    ans = 0
    for k in range(1, min(K + 1, N + 1)):
        for i in range(len(V) - k, len(V) + 1):
            neg = []
            tmp = 0
            for vi in V2[i:i + k]:
                if vi < 0:
                    neg.append(vi)
                tmp += vi
            tmp -= sum(sorted(neg)[:K - k])
            ans = max(ans, tmp)

    print(ans) def main():
    N, K = LI()
    V = LI()
    V2 = V + V

    ans = 0
    for k in range(1, min(K + 1, N + 1)):
        for i in range(len(V) - k, len(V) + 1):
            neg = []
            tmp = 0
            for vi in V2[i:i + k]:
                if vi < 0:
                    neg.append(vi)
                tmp += vi
            tmp -= sum(sorted(neg)[:K - k])
            ans = max(ans, tmp)

    print(ans) main def L(): return sys.stdin.readline().split() def L(): return sys.stdin.readline().split() L MOD = 1000000007 1000000007 MOD alphabets = "abcdefghijklmnopqrstuvwxyz" "abcdefghijklmnopqrstuvwxyz" alphabets def LIR(n): return [LI() for _ in range(n)] def LIR(n): return [LI() for _ in range(n)] LIR dire8 = [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]] [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]] dire8 def I(): return int(sys.stdin.readline().rstrip()) def I(): return int(sys.stdin.readline().rstrip()) I def SL(): return list(sys.stdin.readline().rstrip()) def SL(): return list(sys.stdin.readline().rstrip()) SL def LS(): return [list(x) for x in sys.stdin.readline().split()] def LS(): return [list(x) for x in sys.stdin.readline().split()] LS def LI1(): return [int(x) - 1 for x in sys.stdin.readline().split()] def LI1(): return [int(x) - 1 for x in sys.stdin.readline().split()] LI1 def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI(): return [int(x) for x in sys.stdin.readline().split()] LI def LR(n): return [L() for _ in range(n)] def LR(n): return [L() for _ in range(n)] LR def perm(n, r): return math.factorial(n) // math.factorial(r) def perm(n, r): return math.factorial(n) // math.factorial(r) perm def IR(n): return [I() for _ in range(n)] def IR(n): return [I() for _ in range(n)] IR dire = [[1, 0], [0, 1], [-1, 0], [0, -1]] [[1, 0], [0, 1], [-1, 0], [0, -1]] dire def LIR1(n): return [LI1() for _ in range(n)] def LIR1(n): return [LI1() for _ in range(n)] LIR1 def SR(n): return [S() for _ in range(n)] def SR(n): return [S() for _ in range(n)] SR ALPHABETS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "ABCDEFGHIJKLMNOPQRSTUVWXYZ" ALPHABETS def comb(n, r): return math.factorial(n) // (math.factorial(r) * math.factorial(n-r)) def comb(n, r): return math.factorial(n) // (math.factorial(r) * math.factorial(n-r)) comb INF = float("inf") float("inf") INF
#!usr/bin/env python3
from collections import defaultdict, deque, Counter, OrderedDict
from bisect import bisect_left, bisect_right
from functools import reduce, lru_cache
from heapq import heappush, heappop, heapify

import itertools, bisect
import math, fractions
import sys, copy

def L(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline().rstrip())
def SL(): return list(sys.stdin.readline().rstrip())
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI1(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return [list(x) for x in sys.stdin.readline().split()]
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def LIR1(n): return [LI1() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
def LR(n): return [L() for _ in range(n)]

def perm(n, r): return math.factorial(n) // math.factorial(r)
def comb(n, r): return math.factorial(n) // (math.factorial(r) * math.factorial(n-r))

alphabets = "abcdefghijklmnopqrstuvwxyz"
ALPHABETS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

sys.setrecursionlimit(1000000)
dire = [[1, 0], [0, 1], [-1, 0], [0, -1]]
dire8 = [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]]
MOD = 1000000007
INF = float("inf")

def main():
    N, K = LI()
    V = LI()
    V2 = V + V

    ans = 0
    for k in range(1, min(K + 1, N + 1)):
        for i in range(len(V) - k, len(V) + 1):
            neg = []
            tmp = 0
            for vi in V2[i:i + k]:
                if vi < 0:
                    neg.append(vi)
                tmp += vi
            tmp -= sum(sorted(neg)[:K - k])
            ans = max(ans, tmp)

    print(ans)

if __name__ == '__main__':
    main()