let mod = 1000000007

func readIntPair() -> (Int, Int) {
    let line = readLine()!.split(separator: " ").map({Int($0)!})
    return (line[0], line[1])
}

func readIntArray() -> [Int] {
    readLine()!.split(separator: " ").map({Int($0)!})
}

let (N, M) = readIntPair()
let S = readIntArray(), T = readIntArray()

var dp: [[Int]] = Array.init(repeating: Array.init(repeating: 0, count: M + 1), count: N + 1)
var sum: [[Int]] = Array.init(repeating: Array.init(repeating: 0, count: M + 1), count: N + 1)

(1...N).forEach({ i in
    (1...M).forEach({ j in
        if S[i - 1] == T[j - 1] {
            dp[i][j] = (1 + sum[i - 1][j - 1]) % mod
        } else {
            dp[i][j] = 0
        }
        sum[i][j] = (dp[i][j] + sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] + mod) % mod
    })
})

print((sum[N][M] + 1) % mod)
