def max2(x,y):
    return x if x > y else y
def min2(x,y):
    return x if x < y else y

N, K = map(int, input().split())
V = list(map(int, input().split()))
res = 0
for l in range(K+1):
    for r in range(K+1-l):
        if l+r>N:
            continue
        temp=V[:l]+V[N-r:]
        temp.sort()
        S = sum(temp)
        for cnt in range(min2(K-l-r,l+r)):
            if temp[cnt]<0:
                S -= temp[cnt]
            else:
                break
        res = max2(res, S)
print(res) def max2(x,y):
    return x if x > y else y max2 return x if x > y else y x if x > y else y x > y x y x y x x y y def min2(x,y):
    return x if x < y else y min2 return x if x < y else y x if x < y else y x < y x y x y x x y y 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 res = 0 res 0 for l in range(K+1):
    for r in range(K+1-l):
        if l+r>N:
            continue
        temp=V[:l]+V[N-r:]
        temp.sort()
        S = sum(temp)
        for cnt in range(min2(K-l-r,l+r)):
            if temp[cnt]<0:
                S -= temp[cnt]
            else:
                break
        res = max2(res, S) l range(K+1) range K+1 K 1 for r in range(K+1-l):
        if l+r>N:
            continue
        temp=V[:l]+V[N-r:]
        temp.sort()
        S = sum(temp)
        for cnt in range(min2(K-l-r,l+r)):
            if temp[cnt]<0:
                S -= temp[cnt]
            else:
                break
        res = max2(res, S) r range(K+1-l) range K+1-l K+1 K 1 l if l+r>N:
            continue
         l+r>N l+r l r N continue temp=V[:l]+V[N-r:] temp V[:l]+V[N-r:] V[:l] V :l l V[N-r:] V N-r: N-r N r temp.sort() temp.sort temp sort S = sum(temp) S sum(temp) sum temp for cnt in range(min2(K-l-r,l+r)):
            if temp[cnt]<0:
                S -= temp[cnt]
            else:
                break
         cnt range(min2(K-l-r,l+r)) range min2(K-l-r,l+r) min2 K-l-r K-l K l r l+r l r if temp[cnt]<0:
                S -= temp[cnt]
            else:
                break
         temp[cnt]<0 temp[cnt] temp cnt 0 S -= temp[cnt] S temp[cnt] temp cnt break res = max2(res, S) res max2(res, S) max2 res S print(res) print res V = list(map(int, input().split())) list(map(int, input().split())) V N, K = map(int, input().split()) map(int, input().split()) N res = 0 0 res res = max2(res, S) max2(res, S) res temp=V[:l]+V[N-r:] V[:l]+V[N-r:] temp S -= temp[cnt] temp[cnt] S K = map(int, input().split()) map(int, input().split()) K S = sum(temp) sum(temp) S def min2(x,y):
    return x if x < y else y def min2(x,y):
    return x if x < y else y min2 def max2(x,y):
    return x if x > y else y def max2(x,y):
    return x if x > y else y max2
def max2(x,y):
    return x if x > y else y
def min2(x,y):
    return x if x < y else y

N, K = map(int, input().split())
V = list(map(int, input().split()))
res = 0
for l in range(K+1):
    for r in range(K+1-l):
        if l+r>N:
            continue
        temp=V[:l]+V[N-r:]
        temp.sort()
        S = sum(temp)
        for cnt in range(min2(K-l-r,l+r)):
            if temp[cnt]<0:
                S -= temp[cnt]
            else:
                break
        res = max2(res, S)
print(res)