fun main(args: Array<String>) {
    val (n, m) = readLine()!!.split(' ').map(String::toInt)
    val s = readLine()!!.split(' ').map(String::toInt)
    val t = readLine()!!.split(' ').map(String::toInt)
    val dp = Array(n + 1) { Array(m + 1) { 0L } }
    val sdp = Array(n + 1) { Array(m + 1) { 0L } }
    val po = 1000000007L
    for (i in 1..n) {
        for (j in 1..m) {
            dp[i][j] = if (s[i - 1] == t[j - 1]) (sdp[i - 1][j - 1] + 1) % po else 0
            sdp[i][j] = (sdp[i - 1][j] + sdp[i][j - 1] - sdp[i - 1][j - 1] + dp[i][j]) % po
        }
    }
    println(sdp[n][m] + 1L)
}
