let m = 1000000007
let ( +^ ) x y = (x + y) mod m
let ( -^ ) x y = x +^ (m - y)

let () = Scanf.scanf "%d %d\n" @@ fun n m ->
  let ss = Array.init n @@ fun _ -> Scanf.scanf "%d " @@ fun s -> s in
  let ts = Array.init m @@ fun _ -> Scanf.scanf "%d " @@ fun t -> t in
  let dp = Array.make_matrix (n + 1) (m + 1) 1 in
  for i = 0 to n - 1 do
    for j = 0 to m - 1 do
      dp.(i + 1).(j + 1) <-
        dp.(i).(j + 1) +^ dp.(i + 1).(j)
        -^ if ss.(i) = ts.(j) then 0 else dp.(i).(j)
    done
  done;
  Printf.printf "%d\n" dp.(n).(m)
