from itertools import accumulate
n, k = map(int, input().split())
vs = list(map(int, input().split()))
res = 0
for i in range(min(n,k)+1):
    for j in range(min(n-i,k-i)+1):
        res_tmp = 0
        arr = []
        if i > 0:
            arr += vs[:i]
        if j > 0:
            arr += vs[(n-j):]
        if arr != []:
            arr.sort()
            n_len = len(arr)
            for m in range(min(k-i-j,n_len)):
                if arr[m] >= 0:
                    break
                res_tmp -= arr[m]
            res_tmp += sum(arr)
        res = max(res,res_tmp)
print(res) from itertools import accumulate n, k = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split k vs = list(map(int, input().split())) vs list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split res = 0 res 0 for i in range(min(n,k)+1):
    for j in range(min(n-i,k-i)+1):
        res_tmp = 0
        arr = []
        if i > 0:
            arr += vs[:i]
        if j > 0:
            arr += vs[(n-j):]
        if arr != []:
            arr.sort()
            n_len = len(arr)
            for m in range(min(k-i-j,n_len)):
                if arr[m] >= 0:
                    break
                res_tmp -= arr[m]
            res_tmp += sum(arr)
        res = max(res,res_tmp) i range(min(n,k)+1) range min(n,k)+1 min(n,k) min n k 1 for j in range(min(n-i,k-i)+1):
        res_tmp = 0
        arr = []
        if i > 0:
            arr += vs[:i]
        if j > 0:
            arr += vs[(n-j):]
        if arr != []:
            arr.sort()
            n_len = len(arr)
            for m in range(min(k-i-j,n_len)):
                if arr[m] >= 0:
                    break
                res_tmp -= arr[m]
            res_tmp += sum(arr)
        res = max(res,res_tmp) j range(min(n-i,k-i)+1) range min(n-i,k-i)+1 min(n-i,k-i) min n-i n i k-i k i 1 res_tmp = 0 res_tmp 0 arr = [] arr [] if i > 0:
            arr += vs[:i]
         i > 0 i 0 arr += vs[:i] arr vs[:i] vs :i i if j > 0:
            arr += vs[(n-j):]
         j > 0 j 0 arr += vs[(n-j):] arr vs[(n-j):] vs (n-j): n-j n j if arr != []:
            arr.sort()
            n_len = len(arr)
            for m in range(min(k-i-j,n_len)):
                if arr[m] >= 0:
                    break
                res_tmp -= arr[m]
            res_tmp += sum(arr)
         arr != [] arr [] arr.sort() arr.sort arr sort n_len = len(arr) n_len len(arr) len arr for m in range(min(k-i-j,n_len)):
                if arr[m] >= 0:
                    break
                res_tmp -= arr[m]
             m range(min(k-i-j,n_len)) range min(k-i-j,n_len) min k-i-j k-i k i j n_len if arr[m] >= 0:
                    break
                 arr[m] >= 0 arr[m] arr m 0 break res_tmp -= arr[m] res_tmp arr[m] arr m res_tmp += sum(arr) res_tmp sum(arr) sum arr res = max(res,res_tmp) res max(res,res_tmp) max res res_tmp print(res) print res res_tmp += sum(arr) sum(arr) res_tmp res_tmp -= arr[m] arr[m] res_tmp arr = [] [] arr n_len = len(arr) len(arr) n_len n, k = map(int, input().split()) map(int, input().split()) n vs = list(map(int, input().split())) list(map(int, input().split())) vs res_tmp = 0 0 res_tmp res = max(res,res_tmp) max(res,res_tmp) res k = map(int, input().split()) map(int, input().split()) k res = 0 0 res arr += vs[(n-j):] vs[(n-j):] arr arr += vs[:i] vs[:i] arr
from itertools import accumulate
n, k = map(int, input().split())
vs = list(map(int, input().split()))
res = 0
for i in range(min(n,k)+1):
    for j in range(min(n-i,k-i)+1):
        res_tmp = 0
        arr = []
        if i > 0:
            arr += vs[:i]
        if j > 0:
            arr += vs[(n-j):]
        if arr != []:
            arr.sort()
            n_len = len(arr)
            for m in range(min(k-i-j,n_len)):
                if arr[m] >= 0:
                    break
                res_tmp -= arr[m]
            res_tmp += sum(arr)
        res = max(res,res_tmp)
print(res)