import Data.List (sort)
import Data.Maybe (fromJust)

main :: IO ()
main = do
  (n : x : _) <- map read . words <$> getLine :: IO [Int]
  ss <- sort . map read . words <$> getLine :: IO [Int]
  let
    fs = iterate next (0, map (x `mod`) ss ++ [x])
    next = uncurry next'
    next' i = (,) (succ i) . snd . fromJust . foldr step Nothing
      where
        step y Nothing = Just (y, [])
        step y (Just (y', ys')) = Just (y, ((y + i * y') `mod` m) : ys')
  print . head . snd . head . drop n $ fs

m :: Int
m = 10 ^ 9 + 7
