def main():
    N, K = map(int, input().split())
    V = list(map(int, input().split()))
    ans = 0
    for i in range(K+1):
        cand = []
        for left in range(i+1):
            cand = V[:left]
            right = i - left
            cand += V[max(left,N-right):N]

            cnt = K - i
            n = len(cand)
            tmp = sum(cand)
            cand.sort()
            for c in range(min(cnt,n)):
                if cand[c] < 0:
                    tmp -= cand[c]
                else:
                    break
            ans = max(ans, tmp)


    print(ans)




        

if __name__ == "__main__":
    main() def main():
    N, K = map(int, input().split())
    V = list(map(int, input().split()))
    ans = 0
    for i in range(K+1):
        cand = []
        for left in range(i+1):
            cand = V[:left]
            right = i - left
            cand += V[max(left,N-right):N]

            cnt = K - i
            n = len(cand)
            tmp = sum(cand)
            cand.sort()
            for c in range(min(cnt,n)):
                if cand[c] < 0:
                    tmp -= cand[c]
                else:
                    break
            ans = max(ans, tmp)


    print(ans)




         main N, K = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split K V = list(map(int, input().split())) V list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split ans = 0 ans 0 for i in range(K+1):
        cand = []
        for left in range(i+1):
            cand = V[:left]
            right = i - left
            cand += V[max(left,N-right):N]

            cnt = K - i
            n = len(cand)
            tmp = sum(cand)
            cand.sort()
            for c in range(min(cnt,n)):
                if cand[c] < 0:
                    tmp -= cand[c]
                else:
                    break
            ans = max(ans, tmp)


     i range(K+1) range K+1 K 1 cand = [] cand [] for left in range(i+1):
            cand = V[:left]
            right = i - left
            cand += V[max(left,N-right):N]

            cnt = K - i
            n = len(cand)
            tmp = sum(cand)
            cand.sort()
            for c in range(min(cnt,n)):
                if cand[c] < 0:
                    tmp -= cand[c]
                else:
                    break
            ans = max(ans, tmp)


     left range(i+1) range i+1 i 1 cand = V[:left] cand V[:left] V :left left right = i - left right i - left i left cand += V[max(left,N-right):N] cand V[max(left,N-right):N] V max(left,N-right):N max(left,N-right) max left N-right N right N cnt = K - i cnt K - i K i n = len(cand) n len(cand) len cand tmp = sum(cand) tmp sum(cand) sum cand cand.sort() cand.sort cand sort for c in range(min(cnt,n)):
                if cand[c] < 0:
                    tmp -= cand[c]
                else:
                    break
             c range(min(cnt,n)) range min(cnt,n) min cnt n if cand[c] < 0:
                    tmp -= cand[c]
                else:
                    break
             cand[c] < 0 cand[c] cand c 0 tmp -= cand[c] tmp cand[c] cand c break ans = max(ans, tmp) ans max(ans, tmp) max ans tmp print(ans) print ans if __name__ == "__main__":
    main() __name__ == "__main__" __name__ "__main__" main() main def main():
    N, K = map(int, input().split())
    V = list(map(int, input().split()))
    ans = 0
    for i in range(K+1):
        cand = []
        for left in range(i+1):
            cand = V[:left]
            right = i - left
            cand += V[max(left,N-right):N]

            cnt = K - i
            n = len(cand)
            tmp = sum(cand)
            cand.sort()
            for c in range(min(cnt,n)):
                if cand[c] < 0:
                    tmp -= cand[c]
                else:
                    break
            ans = max(ans, tmp)


    print(ans)




         def main():
    N, K = map(int, input().split())
    V = list(map(int, input().split()))
    ans = 0
    for i in range(K+1):
        cand = []
        for left in range(i+1):
            cand = V[:left]
            right = i - left
            cand += V[max(left,N-right):N]

            cnt = K - i
            n = len(cand)
            tmp = sum(cand)
            cand.sort()
            for c in range(min(cnt,n)):
                if cand[c] < 0:
                    tmp -= cand[c]
                else:
                    break
            ans = max(ans, tmp)


    print(ans)




         main
def main():
    N, K = map(int, input().split())
    V = list(map(int, input().split()))
    ans = 0
    for i in range(K+1):
        cand = []
        for left in range(i+1):
            cand = V[:left]
            right = i - left
            cand += V[max(left,N-right):N]

            cnt = K - i
            n = len(cand)
            tmp = sum(cand)
            cand.sort()
            for c in range(min(cnt,n)):
                if cand[c] < 0:
                    tmp -= cand[c]
                else:
                    break
            ans = max(ans, tmp)


    print(ans)




        

if __name__ == "__main__":
    main()