module Mod = struct
  module type S = sig val modulo : int end
  module Make (S : S) = struct
    open S
    let modulo = modulo
    let (+) a b = (a + b) mod modulo
    let ( * ) a b = (a * b) mod modulo
    let rec ( ** ) a n =
      if n = 0 then 1
      else if n mod 2 = 1 then a * a**(n-1)
      else let t = a ** (n/2) in t * t
    let inv a = a ** (modulo-2)
  end
end
module M = Mod.Make(struct let modulo = 1000000007 end)

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