[n,k],li = [list(map(int,i.split())) for i in open(0)] 
ans = 0
for i in range(1,min(n+1,k+1)):
    for j in range(i+1):
        l = li[:(i-j)] + li[n-j:]
        re_num = min(k-i,len(l))
        l.sort()
        f = 0
        for p in range(re_num):
            if l[p] > 0:
                break
            f += 1
        l = l[f:]
        ans = max(ans,sum(l))
print(ans) list(map(int,i.split())) for i in open(0) for i in open(0) i open(0) open 0 for i in open(0) list(map(int,i.split())) list map(int,i.split()) map int i.split() i.split i split [n,k],li = [list(map(int,i.split())) for i in open(0)] [n,k] n k [list(map(int,i.split())) for i in open(0)] li ans = 0 ans 0 for i in range(1,min(n+1,k+1)):
    for j in range(i+1):
        l = li[:(i-j)] + li[n-j:]
        re_num = min(k-i,len(l))
        l.sort()
        f = 0
        for p in range(re_num):
            if l[p] > 0:
                break
            f += 1
        l = l[f:]
        ans = max(ans,sum(l)) i range(1,min(n+1,k+1)) range 1 min(n+1,k+1) min n+1 n 1 k+1 k 1 for j in range(i+1):
        l = li[:(i-j)] + li[n-j:]
        re_num = min(k-i,len(l))
        l.sort()
        f = 0
        for p in range(re_num):
            if l[p] > 0:
                break
            f += 1
        l = l[f:]
        ans = max(ans,sum(l)) j range(i+1) range i+1 i 1 l = li[:(i-j)] + li[n-j:] l li[:(i-j)] + li[n-j:] li[:(i-j)] li :(i-j) i-j i j li[n-j:] li n-j: n-j n j re_num = min(k-i,len(l)) re_num min(k-i,len(l)) min k-i k i len(l) len l l.sort() l.sort l sort f = 0 f 0 for p in range(re_num):
            if l[p] > 0:
                break
            f += 1
         p range(re_num) range re_num if l[p] > 0:
                break
             l[p] > 0 l[p] l p 0 break f += 1 f 1 l = l[f:] l l[f:] l f: f ans = max(ans,sum(l)) ans max(ans,sum(l)) max ans sum(l) sum l print(ans) print ans ans = 0 0 ans f += 1 1 f l = l[f:] l[f:] l li = [list(map(int,i.split())) for i in open(0)] [list(map(int,i.split())) for i in open(0)] li f = 0 0 f l = li[:(i-j)] + li[n-j:] li[:(i-j)] + li[n-j:] l ans = max(ans,sum(l)) max(ans,sum(l)) ans re_num = min(k-i,len(l)) min(k-i,len(l)) re_num
[n,k],li = [list(map(int,i.split())) for i in open(0)] 
ans = 0
for i in range(1,min(n+1,k+1)):
    for j in range(i+1):
        l = li[:(i-j)] + li[n-j:]
        re_num = min(k-i,len(l))
        l.sort()
        f = 0
        for p in range(re_num):
            if l[p] > 0:
                break
            f += 1
        l = l[f:]
        ans = max(ans,sum(l))
print(ans)