import sys
input = lambda: sys.stdin.readline().rstrip()
input_nums = lambda: list(map(int, input().split()))
from collections import deque

def main():
    N, K = input_nums()
    V = input_nums()
    maxv = 0
    for total in range(min(N, K)+1):
        for a in range(total+1):
            D = deque(V)
            gems = []
            b = total - a
            for i in range(a):
                gems.append(D.pop())
            for i in range(b):
                gems.append(D.popleft())
            gems.sort(reverse=True)
            d = K - (a+b)
            for i in range(d):
                if len(gems) > 0:
                    a = gems.pop()
                    if a < 0:
                        continue
                    else:
                        gems.append(a)
                        break
            maxv = max(maxv, sum(gems))
    print(maxv)

if __name__ == '__main__':
    main() import sys sys input = lambda: sys.stdin.readline().rstrip() input lambda: sys.stdin.readline().rstrip() sys.stdin.readline().rstrip() sys.stdin.readline().rstrip sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline rstrip input_nums = lambda: list(map(int, input().split())) input_nums lambda: list(map(int, input().split())) list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split from collections import deque def main():
    N, K = input_nums()
    V = input_nums()
    maxv = 0
    for total in range(min(N, K)+1):
        for a in range(total+1):
            D = deque(V)
            gems = []
            b = total - a
            for i in range(a):
                gems.append(D.pop())
            for i in range(b):
                gems.append(D.popleft())
            gems.sort(reverse=True)
            d = K - (a+b)
            for i in range(d):
                if len(gems) > 0:
                    a = gems.pop()
                    if a < 0:
                        continue
                    else:
                        gems.append(a)
                        break
            maxv = max(maxv, sum(gems))
    print(maxv) main N, K = input_nums() N input_nums() input_nums K V = input_nums() V input_nums() input_nums maxv = 0 maxv 0 for total in range(min(N, K)+1):
        for a in range(total+1):
            D = deque(V)
            gems = []
            b = total - a
            for i in range(a):
                gems.append(D.pop())
            for i in range(b):
                gems.append(D.popleft())
            gems.sort(reverse=True)
            d = K - (a+b)
            for i in range(d):
                if len(gems) > 0:
                    a = gems.pop()
                    if a < 0:
                        continue
                    else:
                        gems.append(a)
                        break
            maxv = max(maxv, sum(gems))
     total range(min(N, K)+1) range min(N, K)+1 min(N, K) min N K 1 for a in range(total+1):
            D = deque(V)
            gems = []
            b = total - a
            for i in range(a):
                gems.append(D.pop())
            for i in range(b):
                gems.append(D.popleft())
            gems.sort(reverse=True)
            d = K - (a+b)
            for i in range(d):
                if len(gems) > 0:
                    a = gems.pop()
                    if a < 0:
                        continue
                    else:
                        gems.append(a)
                        break
            maxv = max(maxv, sum(gems))
     a range(total+1) range total+1 total 1 D = deque(V) D deque(V) deque V gems = [] gems [] b = total - a b total - a total a for i in range(a):
                gems.append(D.pop())
             i range(a) range a gems.append(D.pop()) gems.append gems append D.pop() D.pop D pop for i in range(b):
                gems.append(D.popleft())
             i range(b) range b gems.append(D.popleft()) gems.append gems append D.popleft() D.popleft D popleft gems.sort(reverse=True) gems.sort gems sort reverse=True reverse True d = K - (a+b) d K - (a+b) K a+b a b for i in range(d):
                if len(gems) > 0:
                    a = gems.pop()
                    if a < 0:
                        continue
                    else:
                        gems.append(a)
                        break
             i range(d) range d if len(gems) > 0:
                    a = gems.pop()
                    if a < 0:
                        continue
                    else:
                        gems.append(a)
                        break
             len(gems) > 0 len(gems) len gems 0 a = gems.pop() a gems.pop() gems.pop gems pop if a < 0:
                        continue
                    else:
                        gems.append(a)
                        break
             a < 0 a 0 continue gems.append(a) gems.append gems append a break maxv = max(maxv, sum(gems)) maxv max(maxv, sum(gems)) max maxv sum(gems) sum gems print(maxv) print maxv if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main input_nums = lambda: list(map(int, input().split())) lambda: list(map(int, input().split())) input_nums def main():
    N, K = input_nums()
    V = input_nums()
    maxv = 0
    for total in range(min(N, K)+1):
        for a in range(total+1):
            D = deque(V)
            gems = []
            b = total - a
            for i in range(a):
                gems.append(D.pop())
            for i in range(b):
                gems.append(D.popleft())
            gems.sort(reverse=True)
            d = K - (a+b)
            for i in range(d):
                if len(gems) > 0:
                    a = gems.pop()
                    if a < 0:
                        continue
                    else:
                        gems.append(a)
                        break
            maxv = max(maxv, sum(gems))
    print(maxv) def main():
    N, K = input_nums()
    V = input_nums()
    maxv = 0
    for total in range(min(N, K)+1):
        for a in range(total+1):
            D = deque(V)
            gems = []
            b = total - a
            for i in range(a):
                gems.append(D.pop())
            for i in range(b):
                gems.append(D.popleft())
            gems.sort(reverse=True)
            d = K - (a+b)
            for i in range(d):
                if len(gems) > 0:
                    a = gems.pop()
                    if a < 0:
                        continue
                    else:
                        gems.append(a)
                        break
            maxv = max(maxv, sum(gems))
    print(maxv) main input = lambda: sys.stdin.readline().rstrip() lambda: sys.stdin.readline().rstrip() input
import sys
input = lambda: sys.stdin.readline().rstrip()
input_nums = lambda: list(map(int, input().split()))
from collections import deque

def main():
    N, K = input_nums()
    V = input_nums()
    maxv = 0
    for total in range(min(N, K)+1):
        for a in range(total+1):
            D = deque(V)
            gems = []
            b = total - a
            for i in range(a):
                gems.append(D.pop())
            for i in range(b):
                gems.append(D.popleft())
            gems.sort(reverse=True)
            d = K - (a+b)
            for i in range(d):
                if len(gems) > 0:
                    a = gems.pop()
                    if a < 0:
                        continue
                    else:
                        gems.append(a)
                        break
            maxv = max(maxv, sum(gems))
    print(maxv)

if __name__ == '__main__':
    main()
