N,M=list(map(int,input().split()))
l=list(map(int,input().split()))
S=min(M,N)
ans=0
for i in range(S+1):
   for j in range(S-i+1):
      mem=l[0:i]+l[N-j:]
      for k in range(min((M-i-j),len(mem))):
         if min(mem)<0:
            mem.remove(min(mem))
      ans=max(ans,sum(mem))
print(ans) N,M=list(map(int,input().split())) N list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split M l=list(map(int,input().split())) l list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split S=min(M,N) S min(M,N) min M N ans=0 ans 0 for i in range(S+1):
   for j in range(S-i+1):
      mem=l[0:i]+l[N-j:]
      for k in range(min((M-i-j),len(mem))):
         if min(mem)<0:
            mem.remove(min(mem))
      ans=max(ans,sum(mem)) i range(S+1) range S+1 S 1 for j in range(S-i+1):
      mem=l[0:i]+l[N-j:]
      for k in range(min((M-i-j),len(mem))):
         if min(mem)<0:
            mem.remove(min(mem))
      ans=max(ans,sum(mem)) j range(S-i+1) range S-i+1 S-i S i 1 mem=l[0:i]+l[N-j:] mem l[0:i]+l[N-j:] l[0:i] l 0:i 0 i l[N-j:] l N-j: N-j N j for k in range(min((M-i-j),len(mem))):
         if min(mem)<0:
            mem.remove(min(mem))
       k range(min((M-i-j),len(mem))) range min((M-i-j),len(mem)) min M-i-j M-i M i j len(mem) len mem if min(mem)<0:
            mem.remove(min(mem))
       min(mem)<0 min(mem) min mem 0 mem.remove(min(mem)) mem.remove mem remove min(mem) min mem ans=max(ans,sum(mem)) ans max(ans,sum(mem)) max ans sum(mem) sum mem print(ans) print ans S=min(M,N) min(M,N) S l=list(map(int,input().split())) list(map(int,input().split())) l M=list(map(int,input().split())) list(map(int,input().split())) M ans=0 0 ans mem=l[0:i]+l[N-j:] l[0:i]+l[N-j:] mem N,M=list(map(int,input().split())) list(map(int,input().split())) N ans=max(ans,sum(mem)) max(ans,sum(mem)) ans
N,M=list(map(int,input().split()))
l=list(map(int,input().split()))
S=min(M,N)
ans=0
for i in range(S+1):
   for j in range(S-i+1):
      mem=l[0:i]+l[N-j:]
      for k in range(min((M-i-j),len(mem))):
         if min(mem)<0:
            mem.remove(min(mem))
      ans=max(ans,sum(mem))
print(ans)