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

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 = foldl1' (\x y -> mod1G7 (x * y))

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

main :: IO ()
main = do
  [n, k] <- getIntList
  as <- getIntegerList
  if all (<= 0) as
    then
      if odd k
        then 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 bs' = filter (\b' -> b' < 0) (reverse bs)
              let as'' = filter (\a -> a > 0) (drop k as')
              let c = if length as'' == 0 || length bs' == 0 then 0 else (prod (bs) `div` (head (bs'))) * (head as'')
              let bs'' = filter (\b' -> b' > 0) (reverse bs)
              let as''' = filter (\a -> a < 0) (drop k as')
              let c' = if length as''' == 0 || length bs'' == 0 then 0 else (prod (bs) `div` (head (bs''))) * (head as''')
              if c == 0 || c' == 0
                then
                  if c == 0 && c' == 0
                    then print $ mod1G7 (prod (take k (filter (\a -> a <= 0) (reverse as'))))
                    else print $ mod1G7 (maximum [c, c'])
                else do
                  let rat = (fromIntegral (head as''')) / (fromIntegral (head (bs'')))
                  let rat' = (fromIntegral (head as'')) / (fromIntegral (head (bs')))
                  if rat > rat'
                    then print c
                    else print c'
