from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter,defaultdict
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq
sys.setrecursionlimit(10**6)
# INF =  float("inf")
INF = 10**18
import bisect
import statistics
mod = 10**9+7
# mod = 998244353

N, K = map(int, input().split())
V = list(map(int, input().split()))

m = 0
for i in range(1, K+1):
    if i <= N:
        for j in range(1,i+1):
            VV = deque(copy.deepcopy(V))
            a = []
            heapq.heapify(a)
            for k in range(j):
                v = VV.popleft()
                heapq.heappush(a,v)
            for k in range(i-j):
                v = VV.pop()
                heapq.heappush(a, v)
            ans = sum(a)
            for k in range(K-i):
                if len(a) > 0:
                    v = heapq.heappop(a)
                    if v < 0:
                        ans -= v
            m = max(m,ans)
    else:
        ans = sum(V)
        a = copy.deepcopy(V)
        heapq.heapify(a)
        for k in range(K-N):
            if len(a) > 0:
                v = heapq.heappop(a)
                if v < 0:
                    ans -= v
        m = max(m, ans)
        break

print(m)



 from sys import stdin import sys sys import math math from functools import reduce import functools functools import itertools itertools from collections import deque,Counter,defaultdict from operator import mul import copy copy import heapq heapq sys.setrecursionlimit(10**6) sys.setrecursionlimit sys setrecursionlimit 10**6 10 6 INF = 10**18 INF 10**18 10 18 import bisect bisect import statistics statistics mod = 10**9+7 mod 10**9+7 10**9 10 9 7 N, K = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split K V = list(map(int, input().split())) V list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split m = 0 m 0 for i in range(1, K+1):
    if i <= N:
        for j in range(1,i+1):
            VV = deque(copy.deepcopy(V))
            a = []
            heapq.heapify(a)
            for k in range(j):
                v = VV.popleft()
                heapq.heappush(a,v)
            for k in range(i-j):
                v = VV.pop()
                heapq.heappush(a, v)
            ans = sum(a)
            for k in range(K-i):
                if len(a) > 0:
                    v = heapq.heappop(a)
                    if v < 0:
                        ans -= v
            m = max(m,ans)
    else:
        ans = sum(V)
        a = copy.deepcopy(V)
        heapq.heapify(a)
        for k in range(K-N):
            if len(a) > 0:
                v = heapq.heappop(a)
                if v < 0:
                    ans -= v
        m = max(m, ans)
        break i range(1, K+1) range 1 K+1 K 1 if i <= N:
        for j in range(1,i+1):
            VV = deque(copy.deepcopy(V))
            a = []
            heapq.heapify(a)
            for k in range(j):
                v = VV.popleft()
                heapq.heappush(a,v)
            for k in range(i-j):
                v = VV.pop()
                heapq.heappush(a, v)
            ans = sum(a)
            for k in range(K-i):
                if len(a) > 0:
                    v = heapq.heappop(a)
                    if v < 0:
                        ans -= v
            m = max(m,ans)
    else:
        ans = sum(V)
        a = copy.deepcopy(V)
        heapq.heapify(a)
        for k in range(K-N):
            if len(a) > 0:
                v = heapq.heappop(a)
                if v < 0:
                    ans -= v
        m = max(m, ans)
        break i <= N i N for j in range(1,i+1):
            VV = deque(copy.deepcopy(V))
            a = []
            heapq.heapify(a)
            for k in range(j):
                v = VV.popleft()
                heapq.heappush(a,v)
            for k in range(i-j):
                v = VV.pop()
                heapq.heappush(a, v)
            ans = sum(a)
            for k in range(K-i):
                if len(a) > 0:
                    v = heapq.heappop(a)
                    if v < 0:
                        ans -= v
            m = max(m,ans)
     j range(1,i+1) range 1 i+1 i 1 VV = deque(copy.deepcopy(V)) VV deque(copy.deepcopy(V)) deque copy.deepcopy(V) copy.deepcopy copy deepcopy V a = [] a [] heapq.heapify(a) heapq.heapify heapq heapify a for k in range(j):
                v = VV.popleft()
                heapq.heappush(a,v)
             k range(j) range j v = VV.popleft() v VV.popleft() VV.popleft VV popleft heapq.heappush(a,v) heapq.heappush heapq heappush a v for k in range(i-j):
                v = VV.pop()
                heapq.heappush(a, v)
             k range(i-j) range i-j i j v = VV.pop() v VV.pop() VV.pop VV pop heapq.heappush(a, v) heapq.heappush heapq heappush a v ans = sum(a) ans sum(a) sum a for k in range(K-i):
                if len(a) > 0:
                    v = heapq.heappop(a)
                    if v < 0:
                        ans -= v
             k range(K-i) range K-i K i if len(a) > 0:
                    v = heapq.heappop(a)
                    if v < 0:
                        ans -= v
             len(a) > 0 len(a) len a 0 v = heapq.heappop(a) v heapq.heappop(a) heapq.heappop heapq heappop a if v < 0:
                        ans -= v
             v < 0 v 0 ans -= v ans v m = max(m,ans) m max(m,ans) max m ans ans = sum(V) ans sum(V) sum V a = copy.deepcopy(V) a copy.deepcopy(V) copy.deepcopy copy deepcopy V heapq.heapify(a) heapq.heapify heapq heapify a for k in range(K-N):
            if len(a) > 0:
                v = heapq.heappop(a)
                if v < 0:
                    ans -= v
         k range(K-N) range K-N K N if len(a) > 0:
                v = heapq.heappop(a)
                if v < 0:
                    ans -= v
         len(a) > 0 len(a) len a 0 v = heapq.heappop(a) v heapq.heappop(a) heapq.heappop heapq heappop a if v < 0:
                    ans -= v
         v < 0 v 0 ans -= v ans v m = max(m, ans) m max(m, ans) max m ans break print(m) print m v = VV.pop() VV.pop() v m = 0 0 m a = copy.deepcopy(V) copy.deepcopy(V) a ans -= v v ans K = map(int, input().split()) map(int, input().split()) K v = VV.popleft() VV.popleft() v v = heapq.heappop(a) heapq.heappop(a) v ans = sum(V) sum(V) ans VV = deque(copy.deepcopy(V)) deque(copy.deepcopy(V)) VV V = list(map(int, input().split())) list(map(int, input().split())) V mod = 10**9+7 10**9+7 mod ans = sum(a) sum(a) ans INF = 10**18 10**18 INF N, K = map(int, input().split()) map(int, input().split()) N v = heapq.heappop(a) heapq.heappop(a) v m = max(m, ans) max(m, ans) m a = [] [] a m = max(m,ans) max(m,ans) m ans -= v v ans
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter,defaultdict
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq
sys.setrecursionlimit(10**6)
# INF =  float("inf")
INF = 10**18
import bisect
import statistics
mod = 10**9+7
# mod = 998244353

N, K = map(int, input().split())
V = list(map(int, input().split()))

m = 0
for i in range(1, K+1):
    if i <= N:
        for j in range(1,i+1):
            VV = deque(copy.deepcopy(V))
            a = []
            heapq.heapify(a)
            for k in range(j):
                v = VV.popleft()
                heapq.heappush(a,v)
            for k in range(i-j):
                v = VV.pop()
                heapq.heappush(a, v)
            ans = sum(a)
            for k in range(K-i):
                if len(a) > 0:
                    v = heapq.heappop(a)
                    if v < 0:
                        ans -= v
            m = max(m,ans)
    else:
        ans = sum(V)
        a = copy.deepcopy(V)
        heapq.heapify(a)
        for k in range(K-N):
            if len(a) > 0:
                v = heapq.heappop(a)
                if v < 0:
                    ans -= v
        m = max(m, ans)
        break

print(m)




