#!/usr/bin/env python3
import sys


def solve(N: int, K: int, V: "List[int]"):

    sum_l = []
    for lk in range(min(N+1, K+1)):
        rk = min(N-lk, K - lk)
        if rk>0:
            q = V[:lk][::-1] + V[-rk:]
        else:
            q = V[:lk][::-1]
        
        m = 0
        sum_=0
        mn = K - (lk+rk)


        for i in range(len(q)):
            q_ = q[i:]
            m = i+mn
            q_s = sorted(q_)
            for x in range(len(q_s)):
                if (q_s[x]<0)&(m>0):
                    m-=1
                else:
                    break
            sum_ = sum(q_s[i+mn-m:])
            sum_l.append(sum_)

    
    print(max(sum_l))
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    V = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, K, V)

if __name__ == '__main__':
    main() import sys sys def solve(N: int, K: int, V: "List[int]"):

    sum_l = []
    for lk in range(min(N+1, K+1)):
        rk = min(N-lk, K - lk)
        if rk>0:
            q = V[:lk][::-1] + V[-rk:]
        else:
            q = V[:lk][::-1]
        
        m = 0
        sum_=0
        mn = K - (lk+rk)


        for i in range(len(q)):
            q_ = q[i:]
            m = i+mn
            q_s = sorted(q_)
            for x in range(len(q_s)):
                if (q_s[x]<0)&(m>0):
                    m-=1
                else:
                    break
            sum_ = sum(q_s[i+mn-m:])
            sum_l.append(sum_)

    
    print(max(sum_l))
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template) solve sum_l = [] sum_l [] for lk in range(min(N+1, K+1)):
        rk = min(N-lk, K - lk)
        if rk>0:
            q = V[:lk][::-1] + V[-rk:]
        else:
            q = V[:lk][::-1]
        
        m = 0
        sum_=0
        mn = K - (lk+rk)


        for i in range(len(q)):
            q_ = q[i:]
            m = i+mn
            q_s = sorted(q_)
            for x in range(len(q_s)):
                if (q_s[x]<0)&(m>0):
                    m-=1
                else:
                    break
            sum_ = sum(q_s[i+mn-m:])
            sum_l.append(sum_)

    
     lk range(min(N+1, K+1)) range min(N+1, K+1) min N+1 N 1 K+1 K 1 rk = min(N-lk, K - lk) rk min(N-lk, K - lk) min N-lk N lk K - lk K lk if rk>0:
            q = V[:lk][::-1] + V[-rk:]
        else:
            q = V[:lk][::-1]
        
         rk>0 rk 0 q = V[:lk][::-1] + V[-rk:] q V[:lk][::-1] + V[-rk:] V[:lk][::-1] [:lk] V :lk lk ::-1 -1 V[-rk:] V -rk: -rk rk q = V[:lk][::-1] q V[:lk][::-1] [:lk] V :lk lk ::-1 -1 m = 0 m 0 sum_=0 sum_ 0 mn = K - (lk+rk) mn K - (lk+rk) K lk+rk lk rk for i in range(len(q)):
            q_ = q[i:]
            m = i+mn
            q_s = sorted(q_)
            for x in range(len(q_s)):
                if (q_s[x]<0)&(m>0):
                    m-=1
                else:
                    break
            sum_ = sum(q_s[i+mn-m:])
            sum_l.append(sum_)

    
     i range(len(q)) range len(q) len q q_ = q[i:] q_ q[i:] q i: i m = i+mn m i+mn i mn q_s = sorted(q_) q_s sorted(q_) sorted q_ for x in range(len(q_s)):
                if (q_s[x]<0)&(m>0):
                    m-=1
                else:
                    break
             x range(len(q_s)) range len(q_s) len q_s if (q_s[x]<0)&(m>0):
                    m-=1
                else:
                    break
             (q_s[x]<0)&(m>0) q_s[x]<0 q_s[x] q_s x 0 m>0 m 0 m-=1 m 1 break sum_ = sum(q_s[i+mn-m:]) sum_ sum(q_s[i+mn-m:]) sum q_s[i+mn-m:] q_s i+mn-m: i+mn-m i+mn i mn m sum_l.append(sum_) sum_l.append sum_l append sum_ print(max(sum_l)) print max(sum_l) max sum_l return N: int N K: int K V: "List[int]" V def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    V = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, K, V) main def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
     iterate_tokens for line in sys.stdin:
            for word in line.split():
                yield word
     line sys.stdin sys stdin for word in line.split():
                yield word
     word line.split() line.split line split yield word word tokens = iterate_tokens() tokens iterate_tokens() iterate_tokens N = int(next(tokens)) N int(next(tokens)) int next(tokens) next tokens K = int(next(tokens)) K int(next(tokens)) int next(tokens) next tokens int(next(tokens)) for _ in range(N) for _ in range(N) _ range(N) range N for _ in range(N) int(next(tokens)) int next(tokens) next tokens V = [int(next(tokens)) for _ in range(N)] V [int(next(tokens)) for _ in range(N)] solve(N, K, V) solve N K V if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    V = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, K, V) def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    V = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, K, V) main def solve(N: int, K: int, V: "List[int]"):

    sum_l = []
    for lk in range(min(N+1, K+1)):
        rk = min(N-lk, K - lk)
        if rk>0:
            q = V[:lk][::-1] + V[-rk:]
        else:
            q = V[:lk][::-1]
        
        m = 0
        sum_=0
        mn = K - (lk+rk)


        for i in range(len(q)):
            q_ = q[i:]
            m = i+mn
            q_s = sorted(q_)
            for x in range(len(q_s)):
                if (q_s[x]<0)&(m>0):
                    m-=1
                else:
                    break
            sum_ = sum(q_s[i+mn-m:])
            sum_l.append(sum_)

    
    print(max(sum_l))
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template) def solve(N: int, K: int, V: "List[int]"):

    sum_l = []
    for lk in range(min(N+1, K+1)):
        rk = min(N-lk, K - lk)
        if rk>0:
            q = V[:lk][::-1] + V[-rk:]
        else:
            q = V[:lk][::-1]
        
        m = 0
        sum_=0
        mn = K - (lk+rk)


        for i in range(len(q)):
            q_ = q[i:]
            m = i+mn
            q_s = sorted(q_)
            for x in range(len(q_s)):
                if (q_s[x]<0)&(m>0):
                    m-=1
                else:
                    break
            sum_ = sum(q_s[i+mn-m:])
            sum_l.append(sum_)

    
    print(max(sum_l))
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template) solve
#!/usr/bin/env python3
import sys


def solve(N: int, K: int, V: "List[int]"):

    sum_l = []
    for lk in range(min(N+1, K+1)):
        rk = min(N-lk, K - lk)
        if rk>0:
            q = V[:lk][::-1] + V[-rk:]
        else:
            q = V[:lk][::-1]
        
        m = 0
        sum_=0
        mn = K - (lk+rk)


        for i in range(len(q)):
            q_ = q[i:]
            m = i+mn
            q_s = sorted(q_)
            for x in range(len(q_s)):
                if (q_s[x]<0)&(m>0):
                    m-=1
                else:
                    break
            sum_ = sum(q_s[i+mn-m:])
            sum_l.append(sum_)

    
    print(max(sum_l))
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    V = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, K, V)

if __name__ == '__main__':
    main()
