import qualified Data.ByteString.Char8 as BS
import Data.Char
import Data.List

main = do
  li <- BS.getLine
  let [n,k] = unfoldr (BS.readInt . BS.dropWhile isSpace) li
  li <- BS.getLine
  let as = unfoldr (BS.readInt . BS.dropWhile isSpace) li
  let ans = compute n k as
  print ans

base = 10^9+7

compute :: Int -> Int -> [Int] -> Integer
compute n k as = flip mod base $ maximum $ zipWith (*) pprods1 (reverse mprods1)
  where
    as1 = map fromIntegral $ sort as
    as2 = reverse as1
    pprods = scanl (*) 1 as2
    mprods = scanl (*) 1 as1
    k1 = succ k
    pprods1 = take k1 (pprods ++ repeat 1)
    mprods1 = take k1 (mprods ++ repeat 1)
