-- https://atcoder.jp/contests/abc173/tasks/abc173_e
-- 正の値になりうるときは、絶対値で降順ソートしたうえで先頭から (k-1) 個とり、残りは積が正の値になる値を加える
-- 正の値にならないときは、絶対値で昇順ソートした上で先頭から k 個とる
-- 0の扱い

import Data.List
import Data.Ord
import Data.Maybe
import Control.Applicative

data ResultType = Positive | Negative | Zero

calcPositive :: Integral a => Int -> [a] -> Maybe a
calcPositive k vs = let (xs, ys) = splitAt (k-1) vs
                        tmp = product xs
                        cmp = if tmp >= 0 then (> 0) else (< 0)
                    in (tmp *) <$> find cmp ys

checkType :: Integral a => Int -> [a] -> [a] -> ResultType
checkType k vs vs' = case () of _ | posLen >= k          -> Positive
                                  | posLen == 0 && odd k -> if hasZero then Zero else Negative
                                  | negLen >= negReq     -> Positive
                                  | otherwise            -> if hasZero then Zero else Negative
  where posLen = length $ filter (>= 0) vs'
        negLen = length $ filter (< 0) vs'
        posDiff = k - posLen
        negReq = if even posDiff then posDiff else posDiff + 1
        hasZero = 0 `elem` vs

main :: IO ()
main = do
  [_, k] <- map read . words <$> getLine :: IO [Int]
  vs <- map read . words <$> getLine :: IO [Integer]
  let vs' = filter (/= 0) vs
      m = floor $ 10 ** 9 + 7
      result = case checkType k vs vs' of
        Positive -> fromMaybe 0 . calcPositive k $ sortOn (Down . abs) vs'
        Negative -> product . take k $ sortOn abs vs'
        Zero     -> 0
  print $ (`mod` m) result
