import Control.Monad
import qualified Data.ByteString.Char8 as BS
import Data.Function
import Data.List
import Data.Maybe
import Data.Ord
import qualified Data.Vector as V
import qualified Data.Vector.Algorithms.Intro as VAIT
import qualified Data.Vector.Generic as VG
import qualified Data.Vector.Generic.Mutable as VGM
import qualified Data.Vector.Mutable as VM
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM

readInt = fst . fromJust . BS.readInt

readInteger = fst . fromJust . BS.readInteger

readIntList = map readInt . BS.words

readIntegerList = map readInteger . BS.words

getIntList = readIntList <$> BS.getLine

getIntegerList = readIntegerList <$> BS.getLine

prod :: VU.Vector Int -> Int
prod = mod1G7 . product . map fromIntegral . VU.toList

sortVecOn :: (Ord a, VG.Vector v b) => (b -> a) -> v b -> v b
sortVecOn f vec = VG.create $ do
  vec <- VG.thaw vec
  VAIT.sortBy (compare `on` f) vec
  return vec

mod1G7 :: Integer -> Int
mod1G7 n = fromIntegral (n `mod` (10 ^ 9 + 7))

main :: IO ()
main = do
  [n, k] <- getIntList
  as <- getIntList
  let as' = VU.fromList as
  if k == n
    then print $ prod as'
    else do
      if VU.all (<= 0) as'
        then
          if odd k
            then print $ prod $ VU.take k $ sortVecOn Down as'
            else print $ prod $ VU.take k $ sortVecOn id as'
        else do
          let as'' = sortVecOn (\a -> (- (abs a))) as'
          let bs = VU.take k as''
          let s = product (map fromIntegral (VU.toList bs))
          if s > 0
            then print $ mod1G7 s
            else do
              let bsr = VU.reverse bs
              let cs = VU.drop k as''
              let bs' = VU.filter (\b' -> b' < 0) bsr
              let cs' = VU.filter (\a -> a > 0) cs
              let d = if VU.length cs' == 0 || VU.length bs' == 0 then 0 else s `div` (fromIntegral (VU.head bs')) * (fromIntegral (VU.head cs'))
              let bs'' = VU.filter (\b' -> b' > 0) bsr
              let cs'' = VU.filter (\a -> a < 0) cs
              let d' = if VU.length cs'' == 0 || VU.length bs'' == 0 then 0 else s `div` (fromIntegral (VU.head bs'')) * (fromIntegral (VU.head cs''))
              if d == 0 && d' == 0
                then print $ prod (VU.take k (VU.filter (\a -> a <= 0) (VU.reverse as')))
                else print $ mod1G7 (maximum [(fromIntegral d), (fromIntegral d')])
