#include<stdio.h>
int main(void){
  char *s="python3 -c\""
"from numpy import*\n"
"n,k,*v=int64(open(0).read().split())\n"
"m=0\n"
"for i in range(n):\n"
" for j in range(min(k,n)-i+1):t=sort(v[:i]+v[:~j:-1]);m=max(m,sum(t)-sum(t[t<0][:k-i-j]))\n"
"print(m)\n"
"\"";
  system(s);
  return 0;
}            