package main
  
import (
    "fmt"
)

func main() {
    const mod = 1e9 + 7
    var n, m int
    fmt.Scan(&n, &m)
    s := make([]int, n)
    t := make([]int, m)
    for i := 0; i < n; i++ {
        fmt.Scan(&s[i])
    }
    for i := 0; i < m; i++ {
        fmt.Scan(&t[i])
    }
    dp := make([][]int, n+1)
    for i := 0; i < n+1; i++ {
        dp[i] = make([]int, m+1)
    }
    for i := 1; i <= n; i++ {
        for j := 1; j <= m; j++ {
            if s[i-1] == t[j-1] {
                dp[i][j] += (dp[i-1][j] + dp[i][j-1] + 1) % mod
            } else {
                dp[i][j] += (dp[i-1][j] + dp[i][j-1] - dp[i-1][j-1]) % mod
            }
        }
    }
    fmt.Println(dp[n][m] + 1)
}
