# ABC128 D
from collections import deque

N,K=map(int,input().split())
V=list(map(int,input().split()))
V=V[:]+V[:]
def check(k):
    res=0
    # 連続する k(K,K-1,...)個の宝石をとる
    # K-k個まで捨ててよい
    for i in range(k+1):
        if k<N:
            v=V[N-k+i:N-k+i+k]
        else:
            v=V[:N]
        v.sort(reverse=True)
        for i in range(K-k):
            if not v:
                break
            if v[-1]<0:
                v.pop()
            else:
                break
        res=max(res,sum(v))
        if not k<N:
            break
    return res

res=0
for k in range(min(N,K)+1):
    res=max(res,check(k))
print(res) from collections import deque 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 V=V[:]+V[:] V V[:]+V[:] V[:] V : V[:] V : def check(k):
    res=0
    # 連続する k(K,K-1,...)個の宝石をとる
    # K-k個まで捨ててよい
    for i in range(k+1):
        if k<N:
            v=V[N-k+i:N-k+i+k]
        else:
            v=V[:N]
        v.sort(reverse=True)
        for i in range(K-k):
            if not v:
                break
            if v[-1]<0:
                v.pop()
            else:
                break
        res=max(res,sum(v))
        if not k<N:
            break
    return res check res=0 res 0 for i in range(k+1):
        if k<N:
            v=V[N-k+i:N-k+i+k]
        else:
            v=V[:N]
        v.sort(reverse=True)
        for i in range(K-k):
            if not v:
                break
            if v[-1]<0:
                v.pop()
            else:
                break
        res=max(res,sum(v))
        if not k<N:
            break
     i range(k+1) range k+1 k 1 if k<N:
            v=V[N-k+i:N-k+i+k]
        else:
            v=V[:N]
         k<N k N v=V[N-k+i:N-k+i+k] v V[N-k+i:N-k+i+k] V N-k+i:N-k+i+k N-k+i N-k N k i N-k+i+k N-k+i N-k N k i k v=V[:N] v V[:N] V :N N v.sort(reverse=True) v.sort v sort reverse=True reverse True for i in range(K-k):
            if not v:
                break
            if v[-1]<0:
                v.pop()
            else:
                break
         i range(K-k) range K-k K k if not v:
                break
             not v v break if v[-1]<0:
                v.pop()
            else:
                break
         v[-1]<0 v[-1] v -1 0 v.pop() v.pop v pop break res=max(res,sum(v)) res max(res,sum(v)) max res sum(v) sum v if not k<N:
            break
     not k<N k<N k N break return res res k k res=0 res 0 for k in range(min(N,K)+1):
    res=max(res,check(k)) k range(min(N,K)+1) range min(N,K)+1 min(N,K) min N K 1 res=max(res,check(k)) res max(res,check(k)) max res check(k) check k print(res) print res res=max(res,check(k)) max(res,check(k)) res V=list(map(int,input().split())) list(map(int,input().split())) V def check(k):
    res=0
    # 連続する k(K,K-1,...)個の宝石をとる
    # K-k個まで捨ててよい
    for i in range(k+1):
        if k<N:
            v=V[N-k+i:N-k+i+k]
        else:
            v=V[:N]
        v.sort(reverse=True)
        for i in range(K-k):
            if not v:
                break
            if v[-1]<0:
                v.pop()
            else:
                break
        res=max(res,sum(v))
        if not k<N:
            break
    return res def check(k):
    res=0
    # 連続する k(K,K-1,...)個の宝石をとる
    # K-k個まで捨ててよい
    for i in range(k+1):
        if k<N:
            v=V[N-k+i:N-k+i+k]
        else:
            v=V[:N]
        v.sort(reverse=True)
        for i in range(K-k):
            if not v:
                break
            if v[-1]<0:
                v.pop()
            else:
                break
        res=max(res,sum(v))
        if not k<N:
            break
    return res check res=0 0 res N,K=map(int,input().split()) map(int,input().split()) N V=V[:]+V[:] V[:]+V[:] V K=map(int,input().split()) map(int,input().split()) K
# ABC128 D
from collections import deque

N,K=map(int,input().split())
V=list(map(int,input().split()))
V=V[:]+V[:]
def check(k):
    res=0
    # 連続する k(K,K-1,...)個の宝石をとる
    # K-k個まで捨ててよい
    for i in range(k+1):
        if k<N:
            v=V[N-k+i:N-k+i+k]
        else:
            v=V[:N]
        v.sort(reverse=True)
        for i in range(K-k):
            if not v:
                break
            if v[-1]<0:
                v.pop()
            else:
                break
        res=max(res,sum(v))
        if not k<N:
            break
    return res

res=0
for k in range(min(N,K)+1):
    res=max(res,check(k))
print(res)