let () =
    let split s =
        let rec loop i cur flag acc =
            if i = String.length s then (
                if flag then cur :: acc else acc
            ) else (
                match flag, s.[i] with
                | true,  ' ' -> loop (i + 1) 0 false (cur :: acc)
                | false, ' ' -> loop (i + 1) 0 false acc
                | true,  v   -> loop (i + 1) (cur * 10 + int_of_char v - 48) true acc
                | false, v   -> loop (i + 1) (cur * 10 + int_of_char v - 48) true acc
            )
        in
        List.rev (loop 0 0 false [])
    in
    let main () =
        let n, m = Scanf.sscanf (read_line ()) "%d %d" (fun n k -> n, k) in
        let arrs = Array.of_list (split (read_line ())) in
        let arrt = Array.of_list (split (read_line ())) in
        let mat = Array.make_matrix (n + 1) (m + 1) 1 in
        let mm = 1000000000 + 7 in
        for y = 1 to n do
            for x = 1 to m do
                mat.(y).(x) <- (mat.(y - 1).(x) + mat.(y).(x - 1) +
                    if arrs.(y - 1) = arrt.(x - 1) then 0 else -mat.(y - 1).(x - 1) + mm) mod mm
            done
        done;
        Printf.printf "%d\n" mat.(n).(m)
    in
    main ()