import sys
from io import StringIO
import unittest
import os

# 再帰処理上限(dfs作成時に設定するのが面倒なので限度近い値を組み込む)
sys.setrecursionlimit(999999999)


# 実装を行う関数
def resolve(test_def_name=""):
    n, k = map(int, input().split())

    v_s = list(map(int, input().split()))
    v_s_rev = list(reversed(v_s))

    ans = 0
    for i in range(min(n, k) + 1):
        left = i

        for j in range(min(n, k) + 1 - i):
            right = j
            remove = min(n, k) - i - j
            if k > n:
                remove += k - n

            val_list = v_s[0:left] + v_s_rev[0:right]
            val_list.sort()
            for loop_k in range(remove):
                if len(val_list) == 0:
                    break
                if len(val_list) < loop_k + 1:
                    break
                if val_list[loop_k] >= 0:
                    break
                val_list[loop_k] = 0

            ans = max(ans, sum(val_list))

    print(ans)


class TestClass(unittest.TestCase):
    def assertIO(self, assert_input, output):
        stdout, sat_in = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(assert_input)
        resolve(sys._getframe().f_back.f_code.co_name)
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, sat_in
        self.assertEqual(out, output)

    def test_input_1(self):
        test_input = """6 4
-10 8 2 1 2 6"""
        output = """14"""
        self.assertIO(test_input, output)

    def test_input_2(self):
        test_input = """6 4
-6 -100 50 -2 -5 -3"""
        output = """44"""
        self.assertIO(test_input, output)

    def test_input_3(self):
        test_input = """6 3
-6 -100 50 -2 -5 -3"""
        output = """0"""
        self.assertIO(test_input, output)

    def test_input_4(self):
        test_input = """6 1
-100 14 1 1 -1 10"""
        output = """10"""
        self.assertIO(test_input, output)

    def test_input_5(self):
        test_input = """6 2
-100 14 1 1 -1 10"""
        output = """10"""
        self.assertIO(test_input, output)

    def test_input_6(self):
        test_input = """6 3
-100 14 1 1 -1 10"""
        output = """14"""
        self.assertIO(test_input, output)

    def test_input_7(self):
        test_input = """6 4
-100 14 1 1 -1 10"""
        output = """24"""
        self.assertIO(test_input, output)

    def test_input_8(self):
        test_input = """6 5
-100 14 1 1 -1 10"""
        output = """25"""
        self.assertIO(test_input, output)

    def test_input_9(self):
        test_input = """6 6
-100 14 1 1 -1 10"""
        output = """26"""
        self.assertIO(test_input, output)

    def test_input_10(self):
        test_input = """6 7
-100 14 1 1 -1 10"""
        output = """26"""
        self.assertIO(test_input, output)

    def test_input_11(self):
        test_input = """7 100
-100 14 -40 1 1 -30 10"""
        output = """26"""
        self.assertIO(test_input, output)

    def test_input_20(self):
        test_input = """50 100
-764207 3102944 -2816278 3249966 5606865 -5997439 4365454 1776907 -1954736 1584162 -437416 -964246 -1828950 -9965518 8636253 -6232397 3421258 -7526570 -7457280 7482600 -1554803 1252 6781335 -3233072 9958581 2263691 -3088247 -2356190 7836991 -1918599 -164787 -9946145 -4801498 3171733 4929342 -6133400 1034826 3746419 -8038615 -7593315 -6791676 5749280 -6696702 6056324 1545511 -2745311 7686370 9321150 -140154 1709122"""
        output = """111018336"""
        self.assertIO(test_input, output)


# 実装orテストの呼び出し
if __name__ == "__main__":
    if os.environ.get("USERNAME") is None:
        # AtCoder提出時の場合
        resolve()

    else:
        # 自PCの場合
        unittest.main() import sys sys from io import StringIO import unittest unittest import os os sys.setrecursionlimit(999999999) sys.setrecursionlimit sys setrecursionlimit 999999999 def resolve(test_def_name=""):
    n, k = map(int, input().split())

    v_s = list(map(int, input().split()))
    v_s_rev = list(reversed(v_s))

    ans = 0
    for i in range(min(n, k) + 1):
        left = i

        for j in range(min(n, k) + 1 - i):
            right = j
            remove = min(n, k) - i - j
            if k > n:
                remove += k - n

            val_list = v_s[0:left] + v_s_rev[0:right]
            val_list.sort()
            for loop_k in range(remove):
                if len(val_list) == 0:
                    break
                if len(val_list) < loop_k + 1:
                    break
                if val_list[loop_k] >= 0:
                    break
                val_list[loop_k] = 0

            ans = max(ans, sum(val_list))

    print(ans) resolve n, k = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split k v_s = list(map(int, input().split())) v_s list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split v_s_rev = list(reversed(v_s)) v_s_rev list(reversed(v_s)) list reversed(v_s) reversed v_s ans = 0 ans 0 for i in range(min(n, k) + 1):
        left = i

        for j in range(min(n, k) + 1 - i):
            right = j
            remove = min(n, k) - i - j
            if k > n:
                remove += k - n

            val_list = v_s[0:left] + v_s_rev[0:right]
            val_list.sort()
            for loop_k in range(remove):
                if len(val_list) == 0:
                    break
                if len(val_list) < loop_k + 1:
                    break
                if val_list[loop_k] >= 0:
                    break
                val_list[loop_k] = 0

            ans = max(ans, sum(val_list))

     i range(min(n, k) + 1) range min(n, k) + 1 min(n, k) min n k 1 left = i left i for j in range(min(n, k) + 1 - i):
            right = j
            remove = min(n, k) - i - j
            if k > n:
                remove += k - n

            val_list = v_s[0:left] + v_s_rev[0:right]
            val_list.sort()
            for loop_k in range(remove):
                if len(val_list) == 0:
                    break
                if len(val_list) < loop_k + 1:
                    break
                if val_list[loop_k] >= 0:
                    break
                val_list[loop_k] = 0

            ans = max(ans, sum(val_list))

     j range(min(n, k) + 1 - i) range min(n, k) + 1 - i min(n, k) + 1 min(n, k) min n k 1 i right = j right j remove = min(n, k) - i - j remove min(n, k) - i - j min(n, k) - i min(n, k) min n k i j if k > n:
                remove += k - n

             k > n k n remove += k - n remove k - n k n val_list = v_s[0:left] + v_s_rev[0:right] val_list v_s[0:left] + v_s_rev[0:right] v_s[0:left] v_s 0:left 0 left v_s_rev[0:right] v_s_rev 0:right 0 right val_list.sort() val_list.sort val_list sort for loop_k in range(remove):
                if len(val_list) == 0:
                    break
                if len(val_list) < loop_k + 1:
                    break
                if val_list[loop_k] >= 0:
                    break
                val_list[loop_k] = 0

             loop_k range(remove) range remove if len(val_list) == 0:
                    break
                 len(val_list) == 0 len(val_list) len val_list 0 break if len(val_list) < loop_k + 1:
                    break
                 len(val_list) < loop_k + 1 len(val_list) len val_list loop_k + 1 loop_k 1 break if val_list[loop_k] >= 0:
                    break
                 val_list[loop_k] >= 0 val_list[loop_k] val_list loop_k 0 break val_list[loop_k] = 0 val_list[loop_k] val_list loop_k 0 ans = max(ans, sum(val_list)) ans max(ans, sum(val_list)) max ans sum(val_list) sum val_list print(ans) print ans test_def_name="" test_def_name "" class TestClass(unittest.TestCase):
    def assertIO(self, assert_input, output):
        stdout, sat_in = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(assert_input)
        resolve(sys._getframe().f_back.f_code.co_name)
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, sat_in
        self.assertEqual(out, output)

    def test_input_1(self):
        test_input = """6 4
-10 8 2 1 2 6"""
        output = """14"""
        self.assertIO(test_input, output)

    def test_input_2(self):
        test_input = """6 4
-6 -100 50 -2 -5 -3"""
        output = """44"""
        self.assertIO(test_input, output)

    def test_input_3(self):
        test_input = """6 3
-6 -100 50 -2 -5 -3"""
        output = """0"""
        self.assertIO(test_input, output)

    def test_input_4(self):
        test_input = """6 1
-100 14 1 1 -1 10"""
        output = """10"""
        self.assertIO(test_input, output)

    def test_input_5(self):
        test_input = """6 2
-100 14 1 1 -1 10"""
        output = """10"""
        self.assertIO(test_input, output)

    def test_input_6(self):
        test_input = """6 3
-100 14 1 1 -1 10"""
        output = """14"""
        self.assertIO(test_input, output)

    def test_input_7(self):
        test_input = """6 4
-100 14 1 1 -1 10"""
        output = """24"""
        self.assertIO(test_input, output)

    def test_input_8(self):
        test_input = """6 5
-100 14 1 1 -1 10"""
        output = """25"""
        self.assertIO(test_input, output)

    def test_input_9(self):
        test_input = """6 6
-100 14 1 1 -1 10"""
        output = """26"""
        self.assertIO(test_input, output)

    def test_input_10(self):
        test_input = """6 7
-100 14 1 1 -1 10"""
        output = """26"""
        self.assertIO(test_input, output)

    def test_input_11(self):
        test_input = """7 100
-100 14 -40 1 1 -30 10"""
        output = """26"""
        self.assertIO(test_input, output)

    def test_input_20(self):
        test_input = """50 100
-764207 3102944 -2816278 3249966 5606865 -5997439 4365454 1776907 -1954736 1584162 -437416 -964246 -1828950 -9965518 8636253 -6232397 3421258 -7526570 -7457280 7482600 -1554803 1252 6781335 -3233072 9958581 2263691 -3088247 -2356190 7836991 -1918599 -164787 -9946145 -4801498 3171733 4929342 -6133400 1034826 3746419 -8038615 -7593315 -6791676 5749280 -6696702 6056324 1545511 -2745311 7686370 9321150 -140154 1709122"""
        output = """111018336"""
        self.assertIO(test_input, output)


# 実装orテストの呼び出し TestClass def assertIO(self, assert_input, output):
        stdout, sat_in = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(assert_input)
        resolve(sys._getframe().f_back.f_code.co_name)
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, sat_in
        self.assertEqual(out, output)

     assertIO stdout, sat_in = sys.stdout, sys.stdin stdout sys.stdout sys stdout sat_in sys.stdin sys stdin sys.stdout, sys.stdin = StringIO(), StringIO(assert_input) sys.stdout sys stdout StringIO() StringIO sys.stdin sys stdin StringIO(assert_input) StringIO assert_input resolve(sys._getframe().f_back.f_code.co_name) resolve sys._getframe().f_back.f_code.co_name sys._getframe().f_back.f_code sys._getframe().f_back sys._getframe() sys._getframe sys _getframe f_back f_code co_name sys.stdout.seek(0) sys.stdout.seek sys.stdout sys stdout seek 0 out = sys.stdout.read()[:-1] out sys.stdout.read()[:-1] sys.stdout.read() sys.stdout.read sys.stdout sys stdout read :-1 -1 sys.stdout, sys.stdin = stdout, sat_in sys.stdout sys stdout stdout sys.stdin sys stdin sat_in self.assertEqual(out, output) self.assertEqual self assertEqual out output self self assert_input assert_input output output def test_input_1(self):
        test_input = """6 4
-10 8 2 1 2 6"""
        output = """14"""
        self.assertIO(test_input, output)

     test_input_1 test_input = """6 4
-10 8 2 1 2 6""" test_input """6 4
-10 8 2 1 2 6""" output = """14""" output """14""" self.assertIO(test_input, output) self.assertIO self assertIO test_input output self self def test_input_2(self):
        test_input = """6 4
-6 -100 50 -2 -5 -3"""
        output = """44"""
        self.assertIO(test_input, output)

     test_input_2 test_input = """6 4
-6 -100 50 -2 -5 -3""" test_input """6 4
-6 -100 50 -2 -5 -3""" output = """44""" output """44""" self.assertIO(test_input, output) self.assertIO self assertIO test_input output self self def test_input_3(self):
        test_input = """6 3
-6 -100 50 -2 -5 -3"""
        output = """0"""
        self.assertIO(test_input, output)

     test_input_3 test_input = """6 3
-6 -100 50 -2 -5 -3""" test_input """6 3
-6 -100 50 -2 -5 -3""" output = """0""" output """0""" self.assertIO(test_input, output) self.assertIO self assertIO test_input output self self def test_input_4(self):
        test_input = """6 1
-100 14 1 1 -1 10"""
        output = """10"""
        self.assertIO(test_input, output)

     test_input_4 test_input = """6 1
-100 14 1 1 -1 10""" test_input """6 1
-100 14 1 1 -1 10""" output = """10""" output """10""" self.assertIO(test_input, output) self.assertIO self assertIO test_input output self self def test_input_5(self):
        test_input = """6 2
-100 14 1 1 -1 10"""
        output = """10"""
        self.assertIO(test_input, output)

     test_input_5 test_input = """6 2
-100 14 1 1 -1 10""" test_input """6 2
-100 14 1 1 -1 10""" output = """10""" output """10""" self.assertIO(test_input, output) self.assertIO self assertIO test_input output self self def test_input_6(self):
        test_input = """6 3
-100 14 1 1 -1 10"""
        output = """14"""
        self.assertIO(test_input, output)

     test_input_6 test_input = """6 3
-100 14 1 1 -1 10""" test_input """6 3
-100 14 1 1 -1 10""" output = """14""" output """14""" self.assertIO(test_input, output) self.assertIO self assertIO test_input output self self def test_input_7(self):
        test_input = """6 4
-100 14 1 1 -1 10"""
        output = """24"""
        self.assertIO(test_input, output)

     test_input_7 test_input = """6 4
-100 14 1 1 -1 10""" test_input """6 4
-100 14 1 1 -1 10""" output = """24""" output """24""" self.assertIO(test_input, output) self.assertIO self assertIO test_input output self self def test_input_8(self):
        test_input = """6 5
-100 14 1 1 -1 10"""
        output = """25"""
        self.assertIO(test_input, output)

     test_input_8 test_input = """6 5
-100 14 1 1 -1 10""" test_input """6 5
-100 14 1 1 -1 10""" output = """25""" output """25""" self.assertIO(test_input, output) self.assertIO self assertIO test_input output self self def test_input_9(self):
        test_input = """6 6
-100 14 1 1 -1 10"""
        output = """26"""
        self.assertIO(test_input, output)

     test_input_9 test_input = """6 6
-100 14 1 1 -1 10""" test_input """6 6
-100 14 1 1 -1 10""" output = """26""" output """26""" self.assertIO(test_input, output) self.assertIO self assertIO test_input output self self def test_input_10(self):
        test_input = """6 7
-100 14 1 1 -1 10"""
        output = """26"""
        self.assertIO(test_input, output)

     test_input_10 test_input = """6 7
-100 14 1 1 -1 10""" test_input """6 7
-100 14 1 1 -1 10""" output = """26""" output """26""" self.assertIO(test_input, output) self.assertIO self assertIO test_input output self self def test_input_11(self):
        test_input = """7 100
-100 14 -40 1 1 -30 10"""
        output = """26"""
        self.assertIO(test_input, output)

     test_input_11 test_input = """7 100
-100 14 -40 1 1 -30 10""" test_input """7 100
-100 14 -40 1 1 -30 10""" output = """26""" output """26""" self.assertIO(test_input, output) self.assertIO self assertIO test_input output self self def test_input_20(self):
        test_input = """50 100
-764207 3102944 -2816278 3249966 5606865 -5997439 4365454 1776907 -1954736 1584162 -437416 -964246 -1828950 -9965518 8636253 -6232397 3421258 -7526570 -7457280 7482600 -1554803 1252 6781335 -3233072 9958581 2263691 -3088247 -2356190 7836991 -1918599 -164787 -9946145 -4801498 3171733 4929342 -6133400 1034826 3746419 -8038615 -7593315 -6791676 5749280 -6696702 6056324 1545511 -2745311 7686370 9321150 -140154 1709122"""
        output = """111018336"""
        self.assertIO(test_input, output)


# 実装orテストの呼び出し test_input_20 test_input = """50 100
-764207 3102944 -2816278 3249966 5606865 -5997439 4365454 1776907 -1954736 1584162 -437416 -964246 -1828950 -9965518 8636253 -6232397 3421258 -7526570 -7457280 7482600 -1554803 1252 6781335 -3233072 9958581 2263691 -3088247 -2356190 7836991 -1918599 -164787 -9946145 -4801498 3171733 4929342 -6133400 1034826 3746419 -8038615 -7593315 -6791676 5749280 -6696702 6056324 1545511 -2745311 7686370 9321150 -140154 1709122""" test_input """50 100
-764207 3102944 -2816278 3249966 5606865 -5997439 4365454 1776907 -1954736 1584162 -437416 -964246 -1828950 -9965518 8636253 -6232397 3421258 -7526570 -7457280 7482600 -1554803 1252 6781335 -3233072 9958581 2263691 -3088247 -2356190 7836991 -1918599 -164787 -9946145 -4801498 3171733 4929342 -6133400 1034826 3746419 -8038615 -7593315 -6791676 5749280 -6696702 6056324 1545511 -2745311 7686370 9321150 -140154 1709122""" output = """111018336""" output """111018336""" self.assertIO(test_input, output) self.assertIO self assertIO test_input output self self unittest.TestCase unittest TestCase if __name__ == "__main__":
    if os.environ.get("USERNAME") is None:
        # AtCoder提出時の場合
        resolve()

    else:
        # 自PCの場合
        unittest.main() __name__ == "__main__" __name__ "__main__" if os.environ.get("USERNAME") is None:
        # AtCoder提出時の場合
        resolve()

    else:
        # 自PCの場合
        unittest.main() os.environ.get("USERNAME") is None os.environ.get("USERNAME") os.environ.get os.environ os environ get "USERNAME" None resolve() resolve unittest.main() unittest.main unittest main def resolve(test_def_name=""):
    n, k = map(int, input().split())

    v_s = list(map(int, input().split()))
    v_s_rev = list(reversed(v_s))

    ans = 0
    for i in range(min(n, k) + 1):
        left = i

        for j in range(min(n, k) + 1 - i):
            right = j
            remove = min(n, k) - i - j
            if k > n:
                remove += k - n

            val_list = v_s[0:left] + v_s_rev[0:right]
            val_list.sort()
            for loop_k in range(remove):
                if len(val_list) == 0:
                    break
                if len(val_list) < loop_k + 1:
                    break
                if val_list[loop_k] >= 0:
                    break
                val_list[loop_k] = 0

            ans = max(ans, sum(val_list))

    print(ans) def resolve(test_def_name=""):
    n, k = map(int, input().split())

    v_s = list(map(int, input().split()))
    v_s_rev = list(reversed(v_s))

    ans = 0
    for i in range(min(n, k) + 1):
        left = i

        for j in range(min(n, k) + 1 - i):
            right = j
            remove = min(n, k) - i - j
            if k > n:
                remove += k - n

            val_list = v_s[0:left] + v_s_rev[0:right]
            val_list.sort()
            for loop_k in range(remove):
                if len(val_list) == 0:
                    break
                if len(val_list) < loop_k + 1:
                    break
                if val_list[loop_k] >= 0:
                    break
                val_list[loop_k] = 0

            ans = max(ans, sum(val_list))

    print(ans) resolve class TestClass(unittest.TestCase):
    def assertIO(self, assert_input, output):
        stdout, sat_in = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(assert_input)
        resolve(sys._getframe().f_back.f_code.co_name)
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, sat_in
        self.assertEqual(out, output)

    def test_input_1(self):
        test_input = """6 4
-10 8 2 1 2 6"""
        output = """14"""
        self.assertIO(test_input, output)

    def test_input_2(self):
        test_input = """6 4
-6 -100 50 -2 -5 -3"""
        output = """44"""
        self.assertIO(test_input, output)

    def test_input_3(self):
        test_input = """6 3
-6 -100 50 -2 -5 -3"""
        output = """0"""
        self.assertIO(test_input, output)

    def test_input_4(self):
        test_input = """6 1
-100 14 1 1 -1 10"""
        output = """10"""
        self.assertIO(test_input, output)

    def test_input_5(self):
        test_input = """6 2
-100 14 1 1 -1 10"""
        output = """10"""
        self.assertIO(test_input, output)

    def test_input_6(self):
        test_input = """6 3
-100 14 1 1 -1 10"""
        output = """14"""
        self.assertIO(test_input, output)

    def test_input_7(self):
        test_input = """6 4
-100 14 1 1 -1 10"""
        output = """24"""
        self.assertIO(test_input, output)

    def test_input_8(self):
        test_input = """6 5
-100 14 1 1 -1 10"""
        output = """25"""
        self.assertIO(test_input, output)

    def test_input_9(self):
        test_input = """6 6
-100 14 1 1 -1 10"""
        output = """26"""
        self.assertIO(test_input, output)

    def test_input_10(self):
        test_input = """6 7
-100 14 1 1 -1 10"""
        output = """26"""
        self.assertIO(test_input, output)

    def test_input_11(self):
        test_input = """7 100
-100 14 -40 1 1 -30 10"""
        output = """26"""
        self.assertIO(test_input, output)

    def test_input_20(self):
        test_input = """50 100
-764207 3102944 -2816278 3249966 5606865 -5997439 4365454 1776907 -1954736 1584162 -437416 -964246 -1828950 -9965518 8636253 -6232397 3421258 -7526570 -7457280 7482600 -1554803 1252 6781335 -3233072 9958581 2263691 -3088247 -2356190 7836991 -1918599 -164787 -9946145 -4801498 3171733 4929342 -6133400 1034826 3746419 -8038615 -7593315 -6791676 5749280 -6696702 6056324 1545511 -2745311 7686370 9321150 -140154 1709122"""
        output = """111018336"""
        self.assertIO(test_input, output)


# 実装orテストの呼び出し class TestClass(unittest.TestCase):
    def assertIO(self, assert_input, output):
        stdout, sat_in = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(assert_input)
        resolve(sys._getframe().f_back.f_code.co_name)
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, sat_in
        self.assertEqual(out, output)

    def test_input_1(self):
        test_input = """6 4
-10 8 2 1 2 6"""
        output = """14"""
        self.assertIO(test_input, output)

    def test_input_2(self):
        test_input = """6 4
-6 -100 50 -2 -5 -3"""
        output = """44"""
        self.assertIO(test_input, output)

    def test_input_3(self):
        test_input = """6 3
-6 -100 50 -2 -5 -3"""
        output = """0"""
        self.assertIO(test_input, output)

    def test_input_4(self):
        test_input = """6 1
-100 14 1 1 -1 10"""
        output = """10"""
        self.assertIO(test_input, output)

    def test_input_5(self):
        test_input = """6 2
-100 14 1 1 -1 10"""
        output = """10"""
        self.assertIO(test_input, output)

    def test_input_6(self):
        test_input = """6 3
-100 14 1 1 -1 10"""
        output = """14"""
        self.assertIO(test_input, output)

    def test_input_7(self):
        test_input = """6 4
-100 14 1 1 -1 10"""
        output = """24"""
        self.assertIO(test_input, output)

    def test_input_8(self):
        test_input = """6 5
-100 14 1 1 -1 10"""
        output = """25"""
        self.assertIO(test_input, output)

    def test_input_9(self):
        test_input = """6 6
-100 14 1 1 -1 10"""
        output = """26"""
        self.assertIO(test_input, output)

    def test_input_10(self):
        test_input = """6 7
-100 14 1 1 -1 10"""
        output = """26"""
        self.assertIO(test_input, output)

    def test_input_11(self):
        test_input = """7 100
-100 14 -40 1 1 -30 10"""
        output = """26"""
        self.assertIO(test_input, output)

    def test_input_20(self):
        test_input = """50 100
-764207 3102944 -2816278 3249966 5606865 -5997439 4365454 1776907 -1954736 1584162 -437416 -964246 -1828950 -9965518 8636253 -6232397 3421258 -7526570 -7457280 7482600 -1554803 1252 6781335 -3233072 9958581 2263691 -3088247 -2356190 7836991 -1918599 -164787 -9946145 -4801498 3171733 4929342 -6133400 1034826 3746419 -8038615 -7593315 -6791676 5749280 -6696702 6056324 1545511 -2745311 7686370 9321150 -140154 1709122"""
        output = """111018336"""
        self.assertIO(test_input, output)


# 実装orテストの呼び出し TestClass
import sys
from io import StringIO
import unittest
import os

# 再帰処理上限(dfs作成時に設定するのが面倒なので限度近い値を組み込む)
sys.setrecursionlimit(999999999)


# 実装を行う関数
def resolve(test_def_name=""):
    n, k = map(int, input().split())

    v_s = list(map(int, input().split()))
    v_s_rev = list(reversed(v_s))

    ans = 0
    for i in range(min(n, k) + 1):
        left = i

        for j in range(min(n, k) + 1 - i):
            right = j
            remove = min(n, k) - i - j
            if k > n:
                remove += k - n

            val_list = v_s[0:left] + v_s_rev[0:right]
            val_list.sort()
            for loop_k in range(remove):
                if len(val_list) == 0:
                    break
                if len(val_list) < loop_k + 1:
                    break
                if val_list[loop_k] >= 0:
                    break
                val_list[loop_k] = 0

            ans = max(ans, sum(val_list))

    print(ans)


class TestClass(unittest.TestCase):
    def assertIO(self, assert_input, output):
        stdout, sat_in = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(assert_input)
        resolve(sys._getframe().f_back.f_code.co_name)
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, sat_in
        self.assertEqual(out, output)

    def test_input_1(self):
        test_input = """6 4
-10 8 2 1 2 6"""
        output = """14"""
        self.assertIO(test_input, output)

    def test_input_2(self):
        test_input = """6 4
-6 -100 50 -2 -5 -3"""
        output = """44"""
        self.assertIO(test_input, output)

    def test_input_3(self):
        test_input = """6 3
-6 -100 50 -2 -5 -3"""
        output = """0"""
        self.assertIO(test_input, output)

    def test_input_4(self):
        test_input = """6 1
-100 14 1 1 -1 10"""
        output = """10"""
        self.assertIO(test_input, output)

    def test_input_5(self):
        test_input = """6 2
-100 14 1 1 -1 10"""
        output = """10"""
        self.assertIO(test_input, output)

    def test_input_6(self):
        test_input = """6 3
-100 14 1 1 -1 10"""
        output = """14"""
        self.assertIO(test_input, output)

    def test_input_7(self):
        test_input = """6 4
-100 14 1 1 -1 10"""
        output = """24"""
        self.assertIO(test_input, output)

    def test_input_8(self):
        test_input = """6 5
-100 14 1 1 -1 10"""
        output = """25"""
        self.assertIO(test_input, output)

    def test_input_9(self):
        test_input = """6 6
-100 14 1 1 -1 10"""
        output = """26"""
        self.assertIO(test_input, output)

    def test_input_10(self):
        test_input = """6 7
-100 14 1 1 -1 10"""
        output = """26"""
        self.assertIO(test_input, output)

    def test_input_11(self):
        test_input = """7 100
-100 14 -40 1 1 -30 10"""
        output = """26"""
        self.assertIO(test_input, output)

    def test_input_20(self):
        test_input = """50 100
-764207 3102944 -2816278 3249966 5606865 -5997439 4365454 1776907 -1954736 1584162 -437416 -964246 -1828950 -9965518 8636253 -6232397 3421258 -7526570 -7457280 7482600 -1554803 1252 6781335 -3233072 9958581 2263691 -3088247 -2356190 7836991 -1918599 -164787 -9946145 -4801498 3171733 4929342 -6133400 1034826 3746419 -8038615 -7593315 -6791676 5749280 -6696702 6056324 1545511 -2745311 7686370 9321150 -140154 1709122"""
        output = """111018336"""
        self.assertIO(test_input, output)


# 実装orテストの呼び出し
if __name__ == "__main__":
    if os.environ.get("USERNAME") is None:
        # AtCoder提出時の場合
        resolve()

    else:
        # 自PCの場合
        unittest.main()
