def main():
    n, k = [int(e) for e in input().split()]
    V = [int(e) for e in input().split()]

    ans = 0
    vc = min(n, k)
    for vci in range(1, vc + 1):
        for vcii in range(vci + 1):
            Hand = []
            for li in range(vcii):
                Hand.append(V[li])

            for ri in range(vci - vcii):
                Hand.append(V[-ri - 1])

            Hand.sort()
            for i in range(min(k - vci, len(Hand))):
                if Hand[i] < 0:
                    Hand[i] = 0

            ans = max(sum(Hand), ans)

    print(ans)


if __name__ == '__main__':
    main() def main():
    n, k = [int(e) for e in input().split()]
    V = [int(e) for e in input().split()]

    ans = 0
    vc = min(n, k)
    for vci in range(1, vc + 1):
        for vcii in range(vci + 1):
            Hand = []
            for li in range(vcii):
                Hand.append(V[li])

            for ri in range(vci - vcii):
                Hand.append(V[-ri - 1])

            Hand.sort()
            for i in range(min(k - vci, len(Hand))):
                if Hand[i] < 0:
                    Hand[i] = 0

            ans = max(sum(Hand), ans)

    print(ans) main int(e) for e in input().split() for e in input().split() e input().split() ().split () input split for e in input().split() int(e) int e n, k = [int(e) for e in input().split()] n [int(e) for e in input().split()] k int(e) for e in input().split() for e in input().split() e input().split() ().split () input split for e in input().split() int(e) int e V = [int(e) for e in input().split()] V [int(e) for e in input().split()] ans = 0 ans 0 vc = min(n, k) vc min(n, k) min n k for vci in range(1, vc + 1):
        for vcii in range(vci + 1):
            Hand = []
            for li in range(vcii):
                Hand.append(V[li])

            for ri in range(vci - vcii):
                Hand.append(V[-ri - 1])

            Hand.sort()
            for i in range(min(k - vci, len(Hand))):
                if Hand[i] < 0:
                    Hand[i] = 0

            ans = max(sum(Hand), ans)

     vci range(1, vc + 1) range 1 vc + 1 vc 1 for vcii in range(vci + 1):
            Hand = []
            for li in range(vcii):
                Hand.append(V[li])

            for ri in range(vci - vcii):
                Hand.append(V[-ri - 1])

            Hand.sort()
            for i in range(min(k - vci, len(Hand))):
                if Hand[i] < 0:
                    Hand[i] = 0

            ans = max(sum(Hand), ans)

     vcii range(vci + 1) range vci + 1 vci 1 Hand = [] Hand [] for li in range(vcii):
                Hand.append(V[li])

             li range(vcii) range vcii Hand.append(V[li]) Hand.append Hand append V[li] V li for ri in range(vci - vcii):
                Hand.append(V[-ri - 1])

             ri range(vci - vcii) range vci - vcii vci vcii Hand.append(V[-ri - 1]) Hand.append Hand append V[-ri - 1] V -ri - 1 -ri ri 1 Hand.sort() Hand.sort Hand sort for i in range(min(k - vci, len(Hand))):
                if Hand[i] < 0:
                    Hand[i] = 0

             i range(min(k - vci, len(Hand))) range min(k - vci, len(Hand)) min k - vci k vci len(Hand) len Hand if Hand[i] < 0:
                    Hand[i] = 0

             Hand[i] < 0 Hand[i] Hand i 0 Hand[i] = 0 Hand[i] Hand i 0 ans = max(sum(Hand), ans) ans max(sum(Hand), ans) max sum(Hand) sum Hand ans print(ans) print ans if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main def main():
    n, k = [int(e) for e in input().split()]
    V = [int(e) for e in input().split()]

    ans = 0
    vc = min(n, k)
    for vci in range(1, vc + 1):
        for vcii in range(vci + 1):
            Hand = []
            for li in range(vcii):
                Hand.append(V[li])

            for ri in range(vci - vcii):
                Hand.append(V[-ri - 1])

            Hand.sort()
            for i in range(min(k - vci, len(Hand))):
                if Hand[i] < 0:
                    Hand[i] = 0

            ans = max(sum(Hand), ans)

    print(ans) def main():
    n, k = [int(e) for e in input().split()]
    V = [int(e) for e in input().split()]

    ans = 0
    vc = min(n, k)
    for vci in range(1, vc + 1):
        for vcii in range(vci + 1):
            Hand = []
            for li in range(vcii):
                Hand.append(V[li])

            for ri in range(vci - vcii):
                Hand.append(V[-ri - 1])

            Hand.sort()
            for i in range(min(k - vci, len(Hand))):
                if Hand[i] < 0:
                    Hand[i] = 0

            ans = max(sum(Hand), ans)

    print(ans) main
def main():
    n, k = [int(e) for e in input().split()]
    V = [int(e) for e in input().split()]

    ans = 0
    vc = min(n, k)
    for vci in range(1, vc + 1):
        for vcii in range(vci + 1):
            Hand = []
            for li in range(vcii):
                Hand.append(V[li])

            for ri in range(vci - vcii):
                Hand.append(V[-ri - 1])

            Hand.sort()
            for i in range(min(k - vci, len(Hand))):
                if Hand[i] < 0:
                    Hand[i] = 0

            ans = max(sum(Hand), ans)

    print(ans)


if __name__ == '__main__':
    main()
