function cut_l() {
  echo $V | cut -d" " -f -$1 2>/dev/null
}
function cut_r() {
  echo $V | cut -d" " -f $((N-$1+1))-$N 2>/dev/null
}
function sum_num() {
  cat - | awk 'BEGIN{total=0} {
    for (i=1; i<=NF; i++) {
      total+=$i
    }
  } END {print total}'
}
function calc_v() {
  l=$1
  r=$2
  rv=$((K-l-r))
  v_s="$(cut_l $l) $(cut_r $r)"
  local t=$(echo $v_s | xargs -n1 | sum_num)
  if [[ $rv != 0 ]]; then 
    (( t-=$(echo $v_s | xargs -n1 | \
    grep "-" | sort -n | \
    head -n ${rv} | sum_num) ))
  fi
  echo $t
}

read N K
read V

while ((${i:=0} <= K))
do
  j=0
  while ((j <= K-i))
  do
    total=$(calc_v $i $j)
    if ((max < total)); then
      max=$total
    fi
    ((j++))
  done
  ((i++))
done

echo ${max:=0}