import qualified Data.ByteString.Char8 as BS
import Data.List
import Data.Maybe
import Data.Ord

readInt = fst . fromJust . BS.readInt

readIntList = map readInt . BS.words

getIntList = readIntList <$> BS.getLine

prod = foldl1' (\x y -> mod1G7 (x * y))

mod1G7 n = n `mod` (10 ^ 9 + 7)

main :: IO ()
main = do
  [n, k] <- getIntList
  as <- getIntList
  if k == n
    then print $ prod as
    else
      if all (<= 0) as
        then
          if odd k
            then
              if elem 0 as
                then print 0
                else print $ prod (take k (sortBy (comparing (\a -> (abs a))) as))
            else print $ prod (take k (sortBy (comparing (\a -> (- (abs a)))) as))
        else do
          let as' = sortBy (comparing (\a -> (- (abs a)))) as
          let bs = take k as'
          let s = prod bs
          if elem 0 bs
            then print 0
            else
              if even (length (filter (\x -> x < 0) bs))
                then print s
                else do
                  let bsr = reverse bs
                  let asr = drop k as'

                  let bs' = filter (\b' -> b' < 0) bsr
                  let as'' = filter (\a -> a > 0) asr
                  let c = if length as'' == 0 || length bs' == 0 then 0 else prod ((head as'') : (delete (head bs') bs))

                  let bs'' = filter (\b' -> b' > 0) bsr
                  let as''' = filter (\a -> a < 0) asr
                  let c' = if length as''' == 0 || length bs'' == 0 then 0 else prod ((head as''') : (delete (head bs'') bs))
                  if c == 0 || c' == 0
                    then
                      if c == 0 && c' == 0
                        then
                          if elem 0 as
                            then print 0
                            else print $ prod (take k (filter (\a -> a <= 0) (reverse as')))
                        else print $ maximum [c, c']
                    else do
                      let rat = abs((fromIntegral (head as'')) / (fromIntegral (head (bs'))))
                      let rat' = abs((fromIntegral (head as''')) / (fromIntegral (head (bs''))))
                      if rat > rat'
                        then print c
                        else print c'
