n,k=map(int,input().split())
a=list(map(int,input().split()))
ans=0
min_nk=min(n,k)
for i in range(min_nk+1):#左
    for j in range(n-min_nk+i,n+1):#右
        count=a[0:i]+a[j:n]
        count.sort()
       # print(count)
        ans=max(ans,sum(count))
        for x in range(1,k-len(count)+1):#消せれば消す
           # print(sum(count[x:]))
            ans=max(ans,sum(count[x:]))
print(ans)

 n,k=map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split k a=list(map(int,input().split())) a list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split ans=0 ans 0 min_nk=min(n,k) min_nk min(n,k) min n k for i in range(min_nk+1):#左
    for j in range(n-min_nk+i,n+1):#右
        count=a[0:i]+a[j:n]
        count.sort()
       # print(count)
        ans=max(ans,sum(count))
        for x in range(1,k-len(count)+1):#消せれば消す
           # print(sum(count[x:]))
            ans=max(ans,sum(count[x:])) i range(min_nk+1) range min_nk+1 min_nk 1 for j in range(n-min_nk+i,n+1):#右
        count=a[0:i]+a[j:n]
        count.sort()
       # print(count)
        ans=max(ans,sum(count))
        for x in range(1,k-len(count)+1):#消せれば消す
           # print(sum(count[x:]))
            ans=max(ans,sum(count[x:])) j range(n-min_nk+i,n+1) range n-min_nk+i n-min_nk n min_nk i n+1 n 1 count=a[0:i]+a[j:n] count a[0:i]+a[j:n] a[0:i] a 0:i 0 i a[j:n] a j:n j n count.sort() count.sort count sort ans=max(ans,sum(count)) ans max(ans,sum(count)) max ans sum(count) sum count for x in range(1,k-len(count)+1):#消せれば消す
           # print(sum(count[x:]))
            ans=max(ans,sum(count[x:])) x range(1,k-len(count)+1) range 1 k-len(count)+1 k-len(count) k len(count) len count 1 ans=max(ans,sum(count[x:])) ans max(ans,sum(count[x:])) max ans sum(count[x:]) sum count[x:] count x: x print(ans) print ans k=map(int,input().split()) map(int,input().split()) k n,k=map(int,input().split()) map(int,input().split()) n ans=max(ans,sum(count)) max(ans,sum(count)) ans min_nk=min(n,k) min(n,k) min_nk ans=0 0 ans a=list(map(int,input().split())) list(map(int,input().split())) a ans=max(ans,sum(count[x:])) max(ans,sum(count[x:])) ans count=a[0:i]+a[j:n] a[0:i]+a[j:n] count
n,k=map(int,input().split())
a=list(map(int,input().split()))
ans=0
min_nk=min(n,k)
for i in range(min_nk+1):#左
    for j in range(n-min_nk+i,n+1):#右
        count=a[0:i]+a[j:n]
        count.sort()
       # print(count)
        ans=max(ans,sum(count))
        for x in range(1,k-len(count)+1):#消せれば消す
           # print(sum(count[x:]))
            ans=max(ans,sum(count[x:]))
print(ans)


