# D - equeue
def main():
    N, K, *V = map(int, open(0).read().split())
    lim = min(N, K)
    available_choices = set()

    for l in range(lim + 1):
        for r in range(lim + 1):
            if l + r > lim:
                break

            choice = V[:l] + V[-r:] if r else V[:l]
            choice.sort()
            cnt_negatives, cnt_rest = sum(i < 0 for i in choice), K - (l + r)

            if cnt_negatives > cnt_rest:
                available_choices.add(sum(choice[cnt_rest:]))
            else:
                available_choices.add(sum(choice[cnt_negatives:]))

    print(max(available_choices))


if __name__ == "__main__":
    main() def main():
    N, K, *V = map(int, open(0).read().split())
    lim = min(N, K)
    available_choices = set()

    for l in range(lim + 1):
        for r in range(lim + 1):
            if l + r > lim:
                break

            choice = V[:l] + V[-r:] if r else V[:l]
            choice.sort()
            cnt_negatives, cnt_rest = sum(i < 0 for i in choice), K - (l + r)

            if cnt_negatives > cnt_rest:
                available_choices.add(sum(choice[cnt_rest:]))
            else:
                available_choices.add(sum(choice[cnt_negatives:]))

    print(max(available_choices)) main N, K, *V = map(int, open(0).read().split()) N map(int, open(0).read().split()) map int open(0).read().split() (0).read().split (0).read() (0).read (0) open 0 read split K *V V lim = min(N, K) lim min(N, K) min N K available_choices = set() available_choices set() set for l in range(lim + 1):
        for r in range(lim + 1):
            if l + r > lim:
                break

            choice = V[:l] + V[-r:] if r else V[:l]
            choice.sort()
            cnt_negatives, cnt_rest = sum(i < 0 for i in choice), K - (l + r)

            if cnt_negatives > cnt_rest:
                available_choices.add(sum(choice[cnt_rest:]))
            else:
                available_choices.add(sum(choice[cnt_negatives:]))

     l range(lim + 1) range lim + 1 lim 1 for r in range(lim + 1):
            if l + r > lim:
                break

            choice = V[:l] + V[-r:] if r else V[:l]
            choice.sort()
            cnt_negatives, cnt_rest = sum(i < 0 for i in choice), K - (l + r)

            if cnt_negatives > cnt_rest:
                available_choices.add(sum(choice[cnt_rest:]))
            else:
                available_choices.add(sum(choice[cnt_negatives:]))

     r range(lim + 1) range lim + 1 lim 1 if l + r > lim:
                break

             l + r > lim l + r l r lim break choice = V[:l] + V[-r:] if r else V[:l] choice V[:l] + V[-r:] if r else V[:l] r V[:l] + V[-r:] V[:l] V :l l V[-r:] V -r: -r r V[:l] V :l l choice.sort() choice.sort choice sort cnt_negatives, cnt_rest = sum(i < 0 for i in choice), K - (l + r) cnt_negatives sum(i < 0 for i in choice) sum i < 0 i 0 cnt_rest K - (l + r) K l + r l r if cnt_negatives > cnt_rest:
                available_choices.add(sum(choice[cnt_rest:]))
            else:
                available_choices.add(sum(choice[cnt_negatives:]))

     cnt_negatives > cnt_rest cnt_negatives cnt_rest available_choices.add(sum(choice[cnt_rest:])) available_choices.add available_choices add sum(choice[cnt_rest:]) sum choice[cnt_rest:] choice cnt_rest: cnt_rest available_choices.add(sum(choice[cnt_negatives:])) available_choices.add available_choices add sum(choice[cnt_negatives:]) sum choice[cnt_negatives:] choice cnt_negatives: cnt_negatives print(max(available_choices)) print max(available_choices) max available_choices if __name__ == "__main__":
    main() __name__ == "__main__" __name__ "__main__" main() main def main():
    N, K, *V = map(int, open(0).read().split())
    lim = min(N, K)
    available_choices = set()

    for l in range(lim + 1):
        for r in range(lim + 1):
            if l + r > lim:
                break

            choice = V[:l] + V[-r:] if r else V[:l]
            choice.sort()
            cnt_negatives, cnt_rest = sum(i < 0 for i in choice), K - (l + r)

            if cnt_negatives > cnt_rest:
                available_choices.add(sum(choice[cnt_rest:]))
            else:
                available_choices.add(sum(choice[cnt_negatives:]))

    print(max(available_choices)) def main():
    N, K, *V = map(int, open(0).read().split())
    lim = min(N, K)
    available_choices = set()

    for l in range(lim + 1):
        for r in range(lim + 1):
            if l + r > lim:
                break

            choice = V[:l] + V[-r:] if r else V[:l]
            choice.sort()
            cnt_negatives, cnt_rest = sum(i < 0 for i in choice), K - (l + r)

            if cnt_negatives > cnt_rest:
                available_choices.add(sum(choice[cnt_rest:]))
            else:
                available_choices.add(sum(choice[cnt_negatives:]))

    print(max(available_choices)) main
# D - equeue
def main():
    N, K, *V = map(int, open(0).read().split())
    lim = min(N, K)
    available_choices = set()

    for l in range(lim + 1):
        for r in range(lim + 1):
            if l + r > lim:
                break

            choice = V[:l] + V[-r:] if r else V[:l]
            choice.sort()
            cnt_negatives, cnt_rest = sum(i < 0 for i in choice), K - (l + r)

            if cnt_negatives > cnt_rest:
                available_choices.add(sum(choice[cnt_rest:]))
            else:
                available_choices.add(sum(choice[cnt_negatives:]))

    print(max(available_choices))


if __name__ == "__main__":
    main()
