def main():
    n,k=map(int,input().split())
    v=list(map(int,input().split()))
    ans=0
    for a in range(min(n,k)+1):
        for b in range(min(n,k)-a+1):
            chk=v[:a]+v[n-b:]
            chk.sort()
            x,s=0,sum(chk)
            while x<k-(a+b) and len(chk)>x:
                s-=min(0,chk[x])
                x+=1
            ans=max(ans,s)
    print(ans)

if __name__ == '__main__':
    main() def main():
    n,k=map(int,input().split())
    v=list(map(int,input().split()))
    ans=0
    for a in range(min(n,k)+1):
        for b in range(min(n,k)-a+1):
            chk=v[:a]+v[n-b:]
            chk.sort()
            x,s=0,sum(chk)
            while x<k-(a+b) and len(chk)>x:
                s-=min(0,chk[x])
                x+=1
            ans=max(ans,s)
    print(ans) main 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 ans=0 ans 0 for a in range(min(n,k)+1):
        for b in range(min(n,k)-a+1):
            chk=v[:a]+v[n-b:]
            chk.sort()
            x,s=0,sum(chk)
            while x<k-(a+b) and len(chk)>x:
                s-=min(0,chk[x])
                x+=1
            ans=max(ans,s)
     a range(min(n,k)+1) range min(n,k)+1 min(n,k) min n k 1 for b in range(min(n,k)-a+1):
            chk=v[:a]+v[n-b:]
            chk.sort()
            x,s=0,sum(chk)
            while x<k-(a+b) and len(chk)>x:
                s-=min(0,chk[x])
                x+=1
            ans=max(ans,s)
     b range(min(n,k)-a+1) range min(n,k)-a+1 min(n,k)-a min(n,k) min n k a 1 chk=v[:a]+v[n-b:] chk v[:a]+v[n-b:] v[:a] v :a a v[n-b:] v n-b: n-b n b chk.sort() chk.sort chk sort x,s=0,sum(chk) x 0 s sum(chk) sum chk while x<k-(a+b) and len(chk)>x:
                s-=min(0,chk[x])
                x+=1
             x<k-(a+b) and len(chk)>x x<k-(a+b) x k-(a+b) k a+b a b len(chk)>x len(chk) len chk x s-=min(0,chk[x]) s min(0,chk[x]) min 0 chk[x] chk x x+=1 x 1 ans=max(ans,s) ans max(ans,s) max ans s print(ans) print ans if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main def main():
    n,k=map(int,input().split())
    v=list(map(int,input().split()))
    ans=0
    for a in range(min(n,k)+1):
        for b in range(min(n,k)-a+1):
            chk=v[:a]+v[n-b:]
            chk.sort()
            x,s=0,sum(chk)
            while x<k-(a+b) and len(chk)>x:
                s-=min(0,chk[x])
                x+=1
            ans=max(ans,s)
    print(ans) def main():
    n,k=map(int,input().split())
    v=list(map(int,input().split()))
    ans=0
    for a in range(min(n,k)+1):
        for b in range(min(n,k)-a+1):
            chk=v[:a]+v[n-b:]
            chk.sort()
            x,s=0,sum(chk)
            while x<k-(a+b) and len(chk)>x:
                s-=min(0,chk[x])
                x+=1
            ans=max(ans,s)
    print(ans) main
def main():
    n,k=map(int,input().split())
    v=list(map(int,input().split()))
    ans=0
    for a in range(min(n,k)+1):
        for b in range(min(n,k)-a+1):
            chk=v[:a]+v[n-b:]
            chk.sort()
            x,s=0,sum(chk)
            while x<k-(a+b) and len(chk)>x:
                s-=min(0,chk[x])
                x+=1
            ans=max(ans,s)
    print(ans)

if __name__ == '__main__':
    main()
