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