use std::io;
use std::cmp;
use std::collections::BinaryHeap;
use std::collections::HashMap;
use std::collections::HashSet;

fn read_line() -> String {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).ok();
    buf
}


fn main() {
    let line:Vec<usize> = read_line().split_whitespace().map(|s| s.parse().unwrap()).collect();

    let n = line[0];
    let m = line[1];

    let S: Vec<usize> = read_line().split_whitespace().map(|s| s.parse().unwrap()).collect();
    let T: Vec<usize> = read_line().split_whitespace().map(|s| s.parse().unwrap()).collect();

    let mut memo = vec![vec![0u64; m+1]; n+1];
    let MOD = 1000_000_007u64;

    memo[n][m] = 1;
    for i in 0..m {
        memo[n][i] = 1;
    }
    for i in 0..n {
        memo[i][m] = 1;
    }
    for i in (0..n).rev() {
        memo[i][m] = memo[i+1][m];
        for j in (0..m).rev() {
            memo[i][j] = memo[i][j + 1];
            for k in i..n {
                if T[j] == S[k] {
                    memo[i][j] += memo[k+1][j+1];
                    memo[i][j] %= MOD;
                }
            }
        }
    }

    println!("{}", memo[0][0]);
}
