import Data.List
main = do
    [n,k] <- map read . words <$> getLine :: IO [Int]
    ak <- map read . words <$> getLine :: IO [Integer]
    let sak = sort (ak :: [Integer])
    let len = length sak
    let s1 = product $ take (k) sak
    let s2 = product $ drop (len - k) sak
    if s1 < s2
        then print $ s2 `mod` (1000000007)
        else print $ s1 `mod` (1000000007)