module Main where

import           Control.Monad
import           Data.List
import           Data.List.Split
import           Data.Array.IO
import qualified Data.Vector as V

main :: IO ()
main = do
  [_, x] <- map read . words <$> getLine :: IO [Int]
  is <- permutations . map read . words <$> getLine :: IO [[Int]]
  ar <- newArray ((0, 0), (x, x)) 10001 :: IO (IOUArray (Int, Int) Int)
  as <- sum <$> mapM (\l -> memo x l ar) is
  print (as `mod` 1000000007)

memo a [b] _ = return (a `mod` b)
memo a (b:bs) ar = do
  x <- readArray ar (a, b)
  case x of
    10001 -> do
      writeArray ar (a, b) (a `mod` b)
      memo (a `mod` b) bs ar 
    _     -> memo x bs ar

