import Data.List
import Data.List.Split
import Data.Array
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 ! (c,n) where
  aas = listArray (1,n) as
  dp = listArray ((0,0),((c+1),(n+1))) [f i j | i<-[0..c+1], j<-[0..n+1]]
  f i j
    |i==0 = 1
    |j==0 = 0
    |otherwise = (dp ! (i,j-1) + dp ! (i-1,j) * aas ! j)`mod`1000000007