use std::io;
use std::str::FromStr;
use std::cmp::max;

static MOD: u64 = 1_000_000_007;

fn input_tuple() -> (u64, u64) {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    let vec: Vec<u64> = line.split_whitespace().map(|s| s.parse().unwrap()).collect();
    (vec[0], vec[1])
}

fn input_vec() -> Vec<u64> {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    line.split_whitespace().map(|s| s.parse().unwrap()).collect()
}

fn main() {
    let (n, m) = input_tuple();
    let s_vec = input_vec();
    let t_vec = input_vec();
    let mut dp = vec![vec![1; t_vec.len() + 1]; s_vec.len() + 1];
    for i in 0..s_vec.len() {
        for j in 0..t_vec.len() {
            dp[i+1][j+1] = dp[i][j+1] % MOD + dp[i+1][j] % MOD;
            if s_vec[i] != t_vec[j] {
                dp[i+1][j+1] -= dp[i][j];
            }
            dp[i+1][j+1] %= MOD;
        }
    }
    println!("{:?}", dp[s_vec.len()][t_vec.len()]);
}
