N, K = map(int, input().split())
V = [int(i) for i in input().split()]
ans = 0
for M in range(K+1):
    for m in range(M+1):
        ls = []
        for i, x in enumerate(V):
            if i < m:
                ls.append(x)
        for i, x in enumerate(V[::-1]):
            if i < min(M-m, N-m):
                ls.append(x)
        ls.sort()
        s = sum(ls)
        for i, x in enumerate(ls):
            if i < K-M and x < 0:
                s -= x
        ans = max(ans, s)
print(ans) 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 V = [int(i) for i in input().split()] V [int(i) for i in input().split()] ans = 0 ans 0 for M in range(K+1):
    for m in range(M+1):
        ls = []
        for i, x in enumerate(V):
            if i < m:
                ls.append(x)
        for i, x in enumerate(V[::-1]):
            if i < min(M-m, N-m):
                ls.append(x)
        ls.sort()
        s = sum(ls)
        for i, x in enumerate(ls):
            if i < K-M and x < 0:
                s -= x
        ans = max(ans, s) M range(K+1) range K+1 K 1 for m in range(M+1):
        ls = []
        for i, x in enumerate(V):
            if i < m:
                ls.append(x)
        for i, x in enumerate(V[::-1]):
            if i < min(M-m, N-m):
                ls.append(x)
        ls.sort()
        s = sum(ls)
        for i, x in enumerate(ls):
            if i < K-M and x < 0:
                s -= x
        ans = max(ans, s) m range(M+1) range M+1 M 1 ls = [] ls [] for i, x in enumerate(V):
            if i < m:
                ls.append(x)
         i x enumerate(V) enumerate V if i < m:
                ls.append(x)
         i < m i m ls.append(x) ls.append ls append x for i, x in enumerate(V[::-1]):
            if i < min(M-m, N-m):
                ls.append(x)
         i x enumerate(V[::-1]) enumerate V[::-1] V ::-1 -1 if i < min(M-m, N-m):
                ls.append(x)
         i < min(M-m, N-m) i min(M-m, N-m) min M-m M m N-m N m ls.append(x) ls.append ls append x ls.sort() ls.sort ls sort s = sum(ls) s sum(ls) sum ls for i, x in enumerate(ls):
            if i < K-M and x < 0:
                s -= x
         i x enumerate(ls) enumerate ls if i < K-M and x < 0:
                s -= x
         i < K-M and x < 0 i < K-M i K-M K M x < 0 x 0 s -= x s x ans = max(ans, s) ans max(ans, s) max ans s print(ans) print ans N, K = map(int, input().split()) map(int, input().split()) N ans = max(ans, s) max(ans, s) ans K = map(int, input().split()) map(int, input().split()) K ls = [] [] ls s = sum(ls) sum(ls) s V = [int(i) for i in input().split()] [int(i) for i in input().split()] V s -= x x s ans = 0 0 ans
N, K = map(int, input().split())
V = [int(i) for i in input().split()]
ans = 0
for M in range(K+1):
    for m in range(M+1):
        ls = []
        for i, x in enumerate(V):
            if i < m:
                ls.append(x)
        for i, x in enumerate(V[::-1]):
            if i < min(M-m, N-m):
                ls.append(x)
        ls.sort()
        s = sum(ls)
        for i, x in enumerate(ls):
            if i < K-M and x < 0:
                s -= x
        ans = max(ans, s)
print(ans)
