stringToInt :: [String] -> [Int]
stringToInt [] = []
stringToInt st = [ read a | a <- st ]

comb :: Int -> [a] -> [[a]]
comb 0 xs = [[]]
comb _ [] = []
comb n (x:xs) = [x:y | y <- comb (n-1) xs] ++ comb n xs

maxN :: Int
maxN = 10^9+6

calN :: Int
calN = 10^9+7

main :: IO ()
main = do
    arg1 <- getLine
    let args1 = words arg1
    let argN = args1 !! 0
    let argK = args1 !! 1

    arg2 <- getLine
    let args2 = stringToInt $ words arg2
    let pickNum = comb (read argK) args2
    let resNum = min maxN (maximum [ product a | a <- pickNum ] `mod` calN)

    print resNum