main = do
  [_,k]<-map read.words<$>getLine
  as<-map read.words<$>getLine
  print$ solve k as

solve k as = max (allPositiveSum - minimum losts) (sum as + maximum losts)
  where
  allPositiveSum = sum.map pos$as
  headKSum = sum.map (pos.negate).take k $ as
  losts = go headKSum as (drop k as)
    where
    go s _ [] = [s]
    go s (a:as) (b:bs) = s : go (s - pos (-a) + pos (-b)) as bs
  pos n = if n>0 then n else 0