fun main(args: Array<String>) {
    val mod = 1000000007L

    val (n, m) = readLine()!!.split(' ').map { it.toInt() }
    val s = readLine()!!.split(' ').map { it.toInt() }
    val t = readLine()!!.split(' ').map { it.toInt() }

    val dp = Array(s.size + 1) { LongArray(t.size + 1) }

    for (i in (0 until n))
        for (j in (0 until m)) {
            val x1 = (dp[i + 1][j] + dp[i][j + 1] + mod - dp[i][j]) % mod
            val x2 = if (s[i] == t[j]) {
                dp[i][j] + 1 % mod
            } else {
                0
            }
            dp[i + 1][j + 1] = (x1 + x2) % mod
        }

    println(dp[n][m] + 1)
}
