#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# 問題：https://atcoder.jp/contests/abc128/tasks/abc128_d

n, k = map(int, input().strip().split())
value = list(map(int, input().strip().split()))
res = 0
for l in range(k+1):
    for r in range(k-l+1):
        if l + r > n:
            continue
        d = k - l - r
        now = 0
        s = []
        for i in range(l):
            now += value[i]
            s.append(value[i])
        for i in range(r):
            now += value[n-i-1]
            s.append(value[n-i-1])
        s.sort()
        for i in range(d):
            if i >= len(s):
                break
            if s[i] > 0:
                break
            now -= s[i]
        res = max(res, now)

print(res)
 n, k = map(int, input().strip().split()) n map(int, input().strip().split()) map int input().strip().split() ().strip().split ().strip() ().strip () input strip split k value = list(map(int, input().strip().split())) value list(map(int, input().strip().split())) list map(int, input().strip().split()) map int input().strip().split() ().strip().split ().strip() ().strip () input strip split res = 0 res 0 for l in range(k+1):
    for r in range(k-l+1):
        if l + r > n:
            continue
        d = k - l - r
        now = 0
        s = []
        for i in range(l):
            now += value[i]
            s.append(value[i])
        for i in range(r):
            now += value[n-i-1]
            s.append(value[n-i-1])
        s.sort()
        for i in range(d):
            if i >= len(s):
                break
            if s[i] > 0:
                break
            now -= s[i]
        res = max(res, now) l range(k+1) range k+1 k 1 for r in range(k-l+1):
        if l + r > n:
            continue
        d = k - l - r
        now = 0
        s = []
        for i in range(l):
            now += value[i]
            s.append(value[i])
        for i in range(r):
            now += value[n-i-1]
            s.append(value[n-i-1])
        s.sort()
        for i in range(d):
            if i >= len(s):
                break
            if s[i] > 0:
                break
            now -= s[i]
        res = max(res, now) r range(k-l+1) range k-l+1 k-l k l 1 if l + r > n:
            continue
         l + r > n l + r l r n continue d = k - l - r d k - l - r k - l k l r now = 0 now 0 s = [] s [] for i in range(l):
            now += value[i]
            s.append(value[i])
         i range(l) range l now += value[i] now value[i] value i s.append(value[i]) s.append s append value[i] value i for i in range(r):
            now += value[n-i-1]
            s.append(value[n-i-1])
         i range(r) range r now += value[n-i-1] now value[n-i-1] value n-i-1 n-i n i 1 s.append(value[n-i-1]) s.append s append value[n-i-1] value n-i-1 n-i n i 1 s.sort() s.sort s sort for i in range(d):
            if i >= len(s):
                break
            if s[i] > 0:
                break
            now -= s[i]
         i range(d) range d if i >= len(s):
                break
             i >= len(s) i len(s) len s break if s[i] > 0:
                break
             s[i] > 0 s[i] s i 0 break now -= s[i] now s[i] s i res = max(res, now) res max(res, now) max res now print(res) print res now += value[n-i-1] value[n-i-1] now n, k = map(int, input().strip().split()) map(int, input().strip().split()) n value = list(map(int, input().strip().split())) list(map(int, input().strip().split())) value s = [] [] s now -= s[i] s[i] now now = 0 0 now now += value[i] value[i] now res = 0 0 res res = max(res, now) max(res, now) res k = map(int, input().strip().split()) map(int, input().strip().split()) k d = k - l - r k - l - r d
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# 問題：https://atcoder.jp/contests/abc128/tasks/abc128_d

n, k = map(int, input().strip().split())
value = list(map(int, input().strip().split()))
res = 0
for l in range(k+1):
    for r in range(k-l+1):
        if l + r > n:
            continue
        d = k - l - r
        now = 0
        s = []
        for i in range(l):
            now += value[i]
            s.append(value[i])
        for i in range(r):
            now += value[n-i-1]
            s.append(value[n-i-1])
        s.sort()
        for i in range(d):
            if i >= len(s):
                break
            if s[i] > 0:
                break
            now -= s[i]
        res = max(res, now)

print(res)

