#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::io::prelude::BufRead;
#[allow(unused_imports)]
use std::io::{stdin, stdout, BufReader, BufWriter, Write};
#[allow(unused_imports)]
use std::mem::swap;
#[allow(unused_imports)]
use std::str::FromStr;

const MOD: usize = 1_000_000_000 + 7;

fn main() {
	let param = read_vector::<usize>();
    let (n, m) = (param[0], param[1]);
    let s1 = read_vector::<usize>();
    let s2 = read_vector::<usize>();
    let mut map1: HashMap<usize, Vec<usize>> = HashMap::new();
    let mut dp = vec![vec![0; m + 1]; n + 1];
    for i in 0..(n + 1) {
        dp[i][0] = 1;
    }
    for i in 0..(m + 1) {
        dp[0][i] = 1;
    }
    for i in 1..(n + 1) {
        if map1.contains_key(&s1[i - 1]) {
            map1.get_mut(&s1[i - 1]).unwrap().push(i);
        } else {
            map1.insert(s1[i - 1], vec![i]);
        }
        for j in 1..(m + 1) {
            dp[i][j] = dp[i][j - 1];
            if map1.contains_key(&s2[j - 1]) {
                for &index in map1.get(&s2[j - 1]).unwrap() {
                    dp[i][j] = (dp[i][j] + dp[index - 1][j - 1]) % MOD;
                }
            }
        }
    }

    println!("{}", dp[n][m]);
   
}

#[allow(dead_code)]
fn read<T>() -> T where T: std::str::FromStr, T::Err: std::fmt::Debug {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    return buf
        .trim()
        .parse()
        .unwrap();
}

#[allow(dead_code)]
fn read_vector<T>() -> Vec<T> where T: std::str::FromStr, T::Err: std::fmt::Debug {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    return buf
        .split_whitespace()
        .map(|s| s.parse().unwrap())
        .collect();
}

#[allow(dead_code)]
fn read_matrix<T>() -> Vec<Vec<T>> where T: std::str::FromStr, T::Err: std::fmt::Debug {
    use std::io::prelude::*;
    let stdin = stdin();
    return stdin
        .lock()
        .lines()
        .map(|line| line
            .unwrap()
            .split_whitespace()
            .map(|s| s.parse().unwrap())
            .collect())
        .collect();
}