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) { 1L }
    val sum = Array(m + 1) { 0L }
    sum[0] = 1
    val po = 1000000007
    for (i in 1..n) {
        for (j in 1..m) {
            sum[j] = (if (s[i - 1] == t[j - 1]) sum[j - 1] + pre[j] else sum[j - 1] + pre[j] - pre[j - 1]) % po
        }
        for (j in 1..m) {
            pre[j] = sum[j]
        }
    }
    println(sum[m])
}
