mod = 10 ** 9 + 7
from collections import deque
import heapq


def iip(listed):
    ret = [int(i) for i in input().split()]
    if len(ret) == 1 and not listed:
        return ret[0]
    return ret


def main():
    r = solve()
    print(r)


def solve():
    N, K = iip(False)
    V = iip(True)
    V2 = [i for i in V]
    V2.reverse()

    mm = 0
    for i in range(N+1):
        for j in range(N+1):
            if i+j > K:
                continue
            if i+j > N:
                continue

            jewels = V[:i]
            jewels.extend(V2[:j])

            zyokyo = K - (i+j)

            while zyokyo >= 1:
                zyokyo -= 1
                if not jewels:
                    break
                mj = min(jewels)
                if min(jewels) < 0:
                    jewels.remove(mj)
                else:
                    break

            mm = max(mm, sum(jewels))
    return mm


#####################################################ライブラリ集ここから

def split_print_space(s):
    print(" ".join([str(i) for i in s]))


def split_print_enter(s):
    print("\n".join([str(i) for i in s]))


def koenai_saidai_x_index(sorted_list, n):
    l = 0
    r = len(sorted_list)
    if len(sorted_list) == 0:
        return False
    if sorted_list[0] > n:
        return False

    while r - l > 1:
        x = (l + r) // 2
        if sorted_list[x] == n:
            return x
        elif sorted_list[x] > n:
            r = x
        else:
            l = x
    return l


def searchsorted(sorted_list, n, side):
    if side not in ["right", "left"]:
        raise Exception("sideはrightかleftで指定してください")

    l = 0
    r = len(sorted_list)

    if n > sorted_list[-1]:
        # print(sorted_list)
        return len(sorted_list)
    if n < sorted_list[0]:
        return 0

    while r - l > 1:
        x = (l + r) // 2
        if sorted_list[x] > n:
            r = x
        elif sorted_list[x] < n:
            l = x
        else:
            if side == "left":
                r = x
            elif side == "right":
                l = x

    if side == "left":
        if sorted_list[l] == n:
            return r - 1
        else:
            return r

    if side == "right":
        if sorted_list[l] == n:
            return l + 1
        else:
            return l


def soinsuu_bunkai(n):
    ret = []
    for i in range(2, int(n ** 0.5) + 1):
        while n % i == 0:
            n //= i
            ret.append(i)
        if i > n:
            break
    if n != 1:
        ret.append(n)
    return ret


def conbination(n, r, mod, test=False):
    if n <= 0:
        return 0
    if r == 0:
        return 1
    if r < 0:
        return 0
    if r == 1:
        return n
    ret = 1
    for i in range(n - r + 1, n + 1):
        ret *= i
        ret = ret % mod

    bunbo = 1
    for i in range(1, r + 1):
        bunbo *= i
        bunbo = bunbo % mod

    ret = (ret * inv(bunbo, mod)) % mod
    if test:
        # print(f"{n}C{r} = {ret}")
        pass
    return ret


def inv(n, mod):
    return power(n, mod - 2)


def power(n, p):
    if p == 0:
        return 1
    if p % 2 == 0:
        return (power(n, p // 2) ** 2) % mod
    if p % 2 == 1:
        return (n * power(n, p - 1)) % mod


if __name__ == "__main__":
    main() mod = 10 ** 9 + 7 mod 10 ** 9 + 7 10 ** 9 10 9 7 from collections import deque import heapq heapq def iip(listed):
    ret = [int(i) for i in input().split()]
    if len(ret) == 1 and not listed:
        return ret[0]
    return ret iip int(i) for i in input().split() for i in input().split() i input().split() ().split () input split for i in input().split() int(i) int i ret = [int(i) for i in input().split()] ret [int(i) for i in input().split()] if len(ret) == 1 and not listed:
        return ret[0]
     len(ret) == 1 and not listed len(ret) == 1 len(ret) len ret 1 not listed listed return ret[0] ret[0] ret 0 return ret ret listed listed def main():
    r = solve()
    print(r) main r = solve() r solve() solve print(r) print r def solve():
    N, K = iip(False)
    V = iip(True)
    V2 = [i for i in V]
    V2.reverse()

    mm = 0
    for i in range(N+1):
        for j in range(N+1):
            if i+j > K:
                continue
            if i+j > N:
                continue

            jewels = V[:i]
            jewels.extend(V2[:j])

            zyokyo = K - (i+j)

            while zyokyo >= 1:
                zyokyo -= 1
                if not jewels:
                    break
                mj = min(jewels)
                if min(jewels) < 0:
                    jewels.remove(mj)
                else:
                    break

            mm = max(mm, sum(jewels))
    return mm


#####################################################ライブラリ集ここから solve N, K = iip(False) N iip(False) iip False K V = iip(True) V iip(True) iip True i for i in V for i in V i V for i in V i V2 = [i for i in V] V2 [i for i in V] V2.reverse() V2.reverse V2 reverse mm = 0 mm 0 for i in range(N+1):
        for j in range(N+1):
            if i+j > K:
                continue
            if i+j > N:
                continue

            jewels = V[:i]
            jewels.extend(V2[:j])

            zyokyo = K - (i+j)

            while zyokyo >= 1:
                zyokyo -= 1
                if not jewels:
                    break
                mj = min(jewels)
                if min(jewels) < 0:
                    jewels.remove(mj)
                else:
                    break

            mm = max(mm, sum(jewels))
     i range(N+1) range N+1 N 1 for j in range(N+1):
            if i+j > K:
                continue
            if i+j > N:
                continue

            jewels = V[:i]
            jewels.extend(V2[:j])

            zyokyo = K - (i+j)

            while zyokyo >= 1:
                zyokyo -= 1
                if not jewels:
                    break
                mj = min(jewels)
                if min(jewels) < 0:
                    jewels.remove(mj)
                else:
                    break

            mm = max(mm, sum(jewels))
     j range(N+1) range N+1 N 1 if i+j > K:
                continue
             i+j > K i+j i j K continue if i+j > N:
                continue

             i+j > N i+j i j N continue jewels = V[:i] jewels V[:i] V :i i jewels.extend(V2[:j]) jewels.extend jewels extend V2[:j] V2 :j j zyokyo = K - (i+j) zyokyo K - (i+j) K i+j i j while zyokyo >= 1:
                zyokyo -= 1
                if not jewels:
                    break
                mj = min(jewels)
                if min(jewels) < 0:
                    jewels.remove(mj)
                else:
                    break

             zyokyo >= 1 zyokyo 1 zyokyo -= 1 zyokyo 1 if not jewels:
                    break
                 not jewels jewels break mj = min(jewels) mj min(jewels) min jewels if min(jewels) < 0:
                    jewels.remove(mj)
                else:
                    break

             min(jewels) < 0 min(jewels) min jewels 0 jewels.remove(mj) jewels.remove jewels remove mj break mm = max(mm, sum(jewels)) mm max(mm, sum(jewels)) max mm sum(jewels) sum jewels return mm mm def split_print_space(s):
    print(" ".join([str(i) for i in s])) split_print_space str(i) for i in s for i in s i s for i in s str(i) str i print(" ".join([str(i) for i in s])) print " ".join([str(i) for i in s]) " ".join " " join [str(i) for i in s] s s def split_print_enter(s):
    print("\n".join([str(i) for i in s])) split_print_enter str(i) for i in s for i in s i s for i in s str(i) str i print("\n".join([str(i) for i in s])) print "\n".join([str(i) for i in s]) "\n".join "\n" join [str(i) for i in s] s s def koenai_saidai_x_index(sorted_list, n):
    l = 0
    r = len(sorted_list)
    if len(sorted_list) == 0:
        return False
    if sorted_list[0] > n:
        return False

    while r - l > 1:
        x = (l + r) // 2
        if sorted_list[x] == n:
            return x
        elif sorted_list[x] > n:
            r = x
        else:
            l = x
    return l koenai_saidai_x_index l = 0 l 0 r = len(sorted_list) r len(sorted_list) len sorted_list if len(sorted_list) == 0:
        return False
     len(sorted_list) == 0 len(sorted_list) len sorted_list 0 return False False if sorted_list[0] > n:
        return False

     sorted_list[0] > n sorted_list[0] sorted_list 0 n return False False while r - l > 1:
        x = (l + r) // 2
        if sorted_list[x] == n:
            return x
        elif sorted_list[x] > n:
            r = x
        else:
            l = x
     r - l > 1 r - l r l 1 x = (l + r) // 2 x (l + r) // 2 l + r l r 2 if sorted_list[x] == n:
            return x
        elif sorted_list[x] > n:
            r = x
        else:
            l = x
     sorted_list[x] == n sorted_list[x] sorted_list x n return x x elif sorted_list[x] > n:
            r = x
         sorted_list[x] > n sorted_list[x] sorted_list x n r = x r x l = x l x return l l sorted_list sorted_list n n def searchsorted(sorted_list, n, side):
    if side not in ["right", "left"]:
        raise Exception("sideはrightかleftで指定してください")

    l = 0
    r = len(sorted_list)

    if n > sorted_list[-1]:
        # print(sorted_list)
        return len(sorted_list)
    if n < sorted_list[0]:
        return 0

    while r - l > 1:
        x = (l + r) // 2
        if sorted_list[x] > n:
            r = x
        elif sorted_list[x] < n:
            l = x
        else:
            if side == "left":
                r = x
            elif side == "right":
                l = x

    if side == "left":
        if sorted_list[l] == n:
            return r - 1
        else:
            return r

    if side == "right":
        if sorted_list[l] == n:
            return l + 1
        else:
            return l searchsorted if side not in ["right", "left"]:
        raise Exception("sideはrightかleftで指定してください")

     side not in ["right", "left"] side ["right", "left"] "right" "left" raise Exception("sideはrightかleftで指定してください") Exception("sideはrightかleftで指定してください") Exception "sideはrightかleftで指定してください" l = 0 l 0 r = len(sorted_list) r len(sorted_list) len sorted_list if n > sorted_list[-1]:
        # print(sorted_list)
        return len(sorted_list)
     n > sorted_list[-1] n sorted_list[-1] sorted_list -1 return len(sorted_list) len(sorted_list) len sorted_list if n < sorted_list[0]:
        return 0

     n < sorted_list[0] n sorted_list[0] sorted_list 0 return 0 0 while r - l > 1:
        x = (l + r) // 2
        if sorted_list[x] > n:
            r = x
        elif sorted_list[x] < n:
            l = x
        else:
            if side == "left":
                r = x
            elif side == "right":
                l = x

     r - l > 1 r - l r l 1 x = (l + r) // 2 x (l + r) // 2 l + r l r 2 if sorted_list[x] > n:
            r = x
        elif sorted_list[x] < n:
            l = x
        else:
            if side == "left":
                r = x
            elif side == "right":
                l = x

     sorted_list[x] > n sorted_list[x] sorted_list x n r = x r x elif sorted_list[x] < n:
            l = x
         sorted_list[x] < n sorted_list[x] sorted_list x n l = x l x if side == "left":
                r = x
            elif side == "right":
                l = x

     side == "left" side "left" r = x r x elif side == "right":
                l = x

     side == "right" side "right" l = x l x if side == "left":
        if sorted_list[l] == n:
            return r - 1
        else:
            return r

     side == "left" side "left" if sorted_list[l] == n:
            return r - 1
        else:
            return r

     sorted_list[l] == n sorted_list[l] sorted_list l n return r - 1 r - 1 r 1 return r r if side == "right":
        if sorted_list[l] == n:
            return l + 1
        else:
            return l side == "right" side "right" if sorted_list[l] == n:
            return l + 1
        else:
            return l sorted_list[l] == n sorted_list[l] sorted_list l n return l + 1 l + 1 l 1 return l l sorted_list sorted_list n n side side def soinsuu_bunkai(n):
    ret = []
    for i in range(2, int(n ** 0.5) + 1):
        while n % i == 0:
            n //= i
            ret.append(i)
        if i > n:
            break
    if n != 1:
        ret.append(n)
    return ret soinsuu_bunkai ret = [] ret [] for i in range(2, int(n ** 0.5) + 1):
        while n % i == 0:
            n //= i
            ret.append(i)
        if i > n:
            break
     i range(2, int(n ** 0.5) + 1) range 2 int(n ** 0.5) + 1 int(n ** 0.5) int n ** 0.5 n 0.5 1 while n % i == 0:
            n //= i
            ret.append(i)
         n % i == 0 n % i n i 0 n //= i n i ret.append(i) ret.append ret append i if i > n:
            break
     i > n i n break if n != 1:
        ret.append(n)
     n != 1 n 1 ret.append(n) ret.append ret append n return ret ret n n def conbination(n, r, mod, test=False):
    if n <= 0:
        return 0
    if r == 0:
        return 1
    if r < 0:
        return 0
    if r == 1:
        return n
    ret = 1
    for i in range(n - r + 1, n + 1):
        ret *= i
        ret = ret % mod

    bunbo = 1
    for i in range(1, r + 1):
        bunbo *= i
        bunbo = bunbo % mod

    ret = (ret * inv(bunbo, mod)) % mod
    if test:
        # print(f"{n}C{r} = {ret}")
        pass
    return ret conbination if n <= 0:
        return 0
     n <= 0 n 0 return 0 0 if r == 0:
        return 1
     r == 0 r 0 return 1 1 if r < 0:
        return 0
     r < 0 r 0 return 0 0 if r == 1:
        return n
     r == 1 r 1 return n n ret = 1 ret 1 for i in range(n - r + 1, n + 1):
        ret *= i
        ret = ret % mod

     i range(n - r + 1, n + 1) range n - r + 1 n - r n r 1 n + 1 n 1 ret *= i ret i ret = ret % mod ret ret % mod ret mod bunbo = 1 bunbo 1 for i in range(1, r + 1):
        bunbo *= i
        bunbo = bunbo % mod

     i range(1, r + 1) range 1 r + 1 r 1 bunbo *= i bunbo i bunbo = bunbo % mod bunbo bunbo % mod bunbo mod ret = (ret * inv(bunbo, mod)) % mod ret (ret * inv(bunbo, mod)) % mod ret * inv(bunbo, mod) ret inv(bunbo, mod) inv bunbo mod mod if test:
        # print(f"{n}C{r} = {ret}")
        pass
     test return ret ret n n r r mod mod test=False test False def inv(n, mod):
    return power(n, mod - 2) inv return power(n, mod - 2) power(n, mod - 2) power n mod - 2 mod 2 n n mod mod def power(n, p):
    if p == 0:
        return 1
    if p % 2 == 0:
        return (power(n, p // 2) ** 2) % mod
    if p % 2 == 1:
        return (n * power(n, p - 1)) % mod power if p == 0:
        return 1
     p == 0 p 0 return 1 1 if p % 2 == 0:
        return (power(n, p // 2) ** 2) % mod
     p % 2 == 0 p % 2 p 2 0 return (power(n, p // 2) ** 2) % mod (power(n, p // 2) ** 2) % mod power(n, p // 2) ** 2 power(n, p // 2) power n p // 2 p 2 2 mod if p % 2 == 1:
        return (n * power(n, p - 1)) % mod p % 2 == 1 p % 2 p 2 1 return (n * power(n, p - 1)) % mod (n * power(n, p - 1)) % mod n * power(n, p - 1) n power(n, p - 1) power n p - 1 p 1 mod n n p p if __name__ == "__main__":
    main() __name__ == "__main__" __name__ "__main__" main() main def soinsuu_bunkai(n):
    ret = []
    for i in range(2, int(n ** 0.5) + 1):
        while n % i == 0:
            n //= i
            ret.append(i)
        if i > n:
            break
    if n != 1:
        ret.append(n)
    return ret def soinsuu_bunkai(n):
    ret = []
    for i in range(2, int(n ** 0.5) + 1):
        while n % i == 0:
            n //= i
            ret.append(i)
        if i > n:
            break
    if n != 1:
        ret.append(n)
    return ret soinsuu_bunkai mod = 10 ** 9 + 7 10 ** 9 + 7 mod def iip(listed):
    ret = [int(i) for i in input().split()]
    if len(ret) == 1 and not listed:
        return ret[0]
    return ret def iip(listed):
    ret = [int(i) for i in input().split()]
    if len(ret) == 1 and not listed:
        return ret[0]
    return ret iip def solve():
    N, K = iip(False)
    V = iip(True)
    V2 = [i for i in V]
    V2.reverse()

    mm = 0
    for i in range(N+1):
        for j in range(N+1):
            if i+j > K:
                continue
            if i+j > N:
                continue

            jewels = V[:i]
            jewels.extend(V2[:j])

            zyokyo = K - (i+j)

            while zyokyo >= 1:
                zyokyo -= 1
                if not jewels:
                    break
                mj = min(jewels)
                if min(jewels) < 0:
                    jewels.remove(mj)
                else:
                    break

            mm = max(mm, sum(jewels))
    return mm


#####################################################ライブラリ集ここから def solve():
    N, K = iip(False)
    V = iip(True)
    V2 = [i for i in V]
    V2.reverse()

    mm = 0
    for i in range(N+1):
        for j in range(N+1):
            if i+j > K:
                continue
            if i+j > N:
                continue

            jewels = V[:i]
            jewels.extend(V2[:j])

            zyokyo = K - (i+j)

            while zyokyo >= 1:
                zyokyo -= 1
                if not jewels:
                    break
                mj = min(jewels)
                if min(jewels) < 0:
                    jewels.remove(mj)
                else:
                    break

            mm = max(mm, sum(jewels))
    return mm


#####################################################ライブラリ集ここから solve def main():
    r = solve()
    print(r) def main():
    r = solve()
    print(r) main def conbination(n, r, mod, test=False):
    if n <= 0:
        return 0
    if r == 0:
        return 1
    if r < 0:
        return 0
    if r == 1:
        return n
    ret = 1
    for i in range(n - r + 1, n + 1):
        ret *= i
        ret = ret % mod

    bunbo = 1
    for i in range(1, r + 1):
        bunbo *= i
        bunbo = bunbo % mod

    ret = (ret * inv(bunbo, mod)) % mod
    if test:
        # print(f"{n}C{r} = {ret}")
        pass
    return ret def conbination(n, r, mod, test=False):
    if n <= 0:
        return 0
    if r == 0:
        return 1
    if r < 0:
        return 0
    if r == 1:
        return n
    ret = 1
    for i in range(n - r + 1, n + 1):
        ret *= i
        ret = ret % mod

    bunbo = 1
    for i in range(1, r + 1):
        bunbo *= i
        bunbo = bunbo % mod

    ret = (ret * inv(bunbo, mod)) % mod
    if test:
        # print(f"{n}C{r} = {ret}")
        pass
    return ret conbination def split_print_space(s):
    print(" ".join([str(i) for i in s])) def split_print_space(s):
    print(" ".join([str(i) for i in s])) split_print_space def split_print_enter(s):
    print("\n".join([str(i) for i in s])) def split_print_enter(s):
    print("\n".join([str(i) for i in s])) split_print_enter def koenai_saidai_x_index(sorted_list, n):
    l = 0
    r = len(sorted_list)
    if len(sorted_list) == 0:
        return False
    if sorted_list[0] > n:
        return False

    while r - l > 1:
        x = (l + r) // 2
        if sorted_list[x] == n:
            return x
        elif sorted_list[x] > n:
            r = x
        else:
            l = x
    return l def koenai_saidai_x_index(sorted_list, n):
    l = 0
    r = len(sorted_list)
    if len(sorted_list) == 0:
        return False
    if sorted_list[0] > n:
        return False

    while r - l > 1:
        x = (l + r) // 2
        if sorted_list[x] == n:
            return x
        elif sorted_list[x] > n:
            r = x
        else:
            l = x
    return l koenai_saidai_x_index def searchsorted(sorted_list, n, side):
    if side not in ["right", "left"]:
        raise Exception("sideはrightかleftで指定してください")

    l = 0
    r = len(sorted_list)

    if n > sorted_list[-1]:
        # print(sorted_list)
        return len(sorted_list)
    if n < sorted_list[0]:
        return 0

    while r - l > 1:
        x = (l + r) // 2
        if sorted_list[x] > n:
            r = x
        elif sorted_list[x] < n:
            l = x
        else:
            if side == "left":
                r = x
            elif side == "right":
                l = x

    if side == "left":
        if sorted_list[l] == n:
            return r - 1
        else:
            return r

    if side == "right":
        if sorted_list[l] == n:
            return l + 1
        else:
            return l def searchsorted(sorted_list, n, side):
    if side not in ["right", "left"]:
        raise Exception("sideはrightかleftで指定してください")

    l = 0
    r = len(sorted_list)

    if n > sorted_list[-1]:
        # print(sorted_list)
        return len(sorted_list)
    if n < sorted_list[0]:
        return 0

    while r - l > 1:
        x = (l + r) // 2
        if sorted_list[x] > n:
            r = x
        elif sorted_list[x] < n:
            l = x
        else:
            if side == "left":
                r = x
            elif side == "right":
                l = x

    if side == "left":
        if sorted_list[l] == n:
            return r - 1
        else:
            return r

    if side == "right":
        if sorted_list[l] == n:
            return l + 1
        else:
            return l searchsorted def inv(n, mod):
    return power(n, mod - 2) def inv(n, mod):
    return power(n, mod - 2) inv def power(n, p):
    if p == 0:
        return 1
    if p % 2 == 0:
        return (power(n, p // 2) ** 2) % mod
    if p % 2 == 1:
        return (n * power(n, p - 1)) % mod def power(n, p):
    if p == 0:
        return 1
    if p % 2 == 0:
        return (power(n, p // 2) ** 2) % mod
    if p % 2 == 1:
        return (n * power(n, p - 1)) % mod power
mod = 10 ** 9 + 7
from collections import deque
import heapq


def iip(listed):
    ret = [int(i) for i in input().split()]
    if len(ret) == 1 and not listed:
        return ret[0]
    return ret


def main():
    r = solve()
    print(r)


def solve():
    N, K = iip(False)
    V = iip(True)
    V2 = [i for i in V]
    V2.reverse()

    mm = 0
    for i in range(N+1):
        for j in range(N+1):
            if i+j > K:
                continue
            if i+j > N:
                continue

            jewels = V[:i]
            jewels.extend(V2[:j])

            zyokyo = K - (i+j)

            while zyokyo >= 1:
                zyokyo -= 1
                if not jewels:
                    break
                mj = min(jewels)
                if min(jewels) < 0:
                    jewels.remove(mj)
                else:
                    break

            mm = max(mm, sum(jewels))
    return mm


#####################################################ライブラリ集ここから

def split_print_space(s):
    print(" ".join([str(i) for i in s]))


def split_print_enter(s):
    print("\n".join([str(i) for i in s]))


def koenai_saidai_x_index(sorted_list, n):
    l = 0
    r = len(sorted_list)
    if len(sorted_list) == 0:
        return False
    if sorted_list[0] > n:
        return False

    while r - l > 1:
        x = (l + r) // 2
        if sorted_list[x] == n:
            return x
        elif sorted_list[x] > n:
            r = x
        else:
            l = x
    return l


def searchsorted(sorted_list, n, side):
    if side not in ["right", "left"]:
        raise Exception("sideはrightかleftで指定してください")

    l = 0
    r = len(sorted_list)

    if n > sorted_list[-1]:
        # print(sorted_list)
        return len(sorted_list)
    if n < sorted_list[0]:
        return 0

    while r - l > 1:
        x = (l + r) // 2
        if sorted_list[x] > n:
            r = x
        elif sorted_list[x] < n:
            l = x
        else:
            if side == "left":
                r = x
            elif side == "right":
                l = x

    if side == "left":
        if sorted_list[l] == n:
            return r - 1
        else:
            return r

    if side == "right":
        if sorted_list[l] == n:
            return l + 1
        else:
            return l


def soinsuu_bunkai(n):
    ret = []
    for i in range(2, int(n ** 0.5) + 1):
        while n % i == 0:
            n //= i
            ret.append(i)
        if i > n:
            break
    if n != 1:
        ret.append(n)
    return ret


def conbination(n, r, mod, test=False):
    if n <= 0:
        return 0
    if r == 0:
        return 1
    if r < 0:
        return 0
    if r == 1:
        return n
    ret = 1
    for i in range(n - r + 1, n + 1):
        ret *= i
        ret = ret % mod

    bunbo = 1
    for i in range(1, r + 1):
        bunbo *= i
        bunbo = bunbo % mod

    ret = (ret * inv(bunbo, mod)) % mod
    if test:
        # print(f"{n}C{r} = {ret}")
        pass
    return ret


def inv(n, mod):
    return power(n, mod - 2)


def power(n, p):
    if p == 0:
        return 1
    if p % 2 == 0:
        return (power(n, p // 2) ** 2) % mod
    if p % 2 == 1:
        return (n * power(n, p - 1)) % mod


if __name__ == "__main__":
    main()