import Data.List
import Data.List.Split
import Control.Monad
import qualified Data.Vector as V
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VM
main = mapM_ (print . solve) . chunksOf 3 . map (map read . words) . lines =<< getContents
solve::[[Int]]->Int
solve [[n,c],as,bs] = if as/=bs then -1 else dp VU.! (idx c n)  where
  vas = VU.fromList as
  idx i j = i*(n+1)+j
  dp = VU.create $ do
    dp <- VM.new ((c+1)*(n+1))
    forM_ [0..n] $ \i -> VM.write dp (idx 0 i) 1
    forM_ [1..c] $ \i -> VM.write dp (idx i 0) 0
    forM_ [1..c] $ \i ->
      forM_ [1..n] $ \j -> do
        a <- VM.read dp (idx i (j-1))
        b <- VM.read dp (idx (i-1) j)
        VM.write dp (idx i j) ((a+b*vas VU.! (j-1))`mod`1000000007)
    return dp