parseInt(x) = parse(Int,x)

function main()
    MOD = 1000000007
    n, m = map(parseInt, split(readline()))
    a = map(parseInt, split(readline()))
    b = map(parseInt, split(readline()))

    ans = 0
    dp = zeros(Int, 2, n)

    ans = 1

    pre = 1
    for i in 1:n
        if a[i] == b[1]
            dp[1,i] = pre + 1
            ans += 1
        else 
            dp[1,i] = pre
        end
        pre = dp[1,i]
    end

    for i in 2:m
        cur = (i%2 == 1) ? 1 : 2
        ant = (i%2 == 1) ? 2 : 1

        pre = 1
        for j in 1:n
            if a[j] == b[i]
                dp[cur,j] = pre
                ans += pre
            else
                dp[cur,j] = 0
            end
            pre = dp[ant,j]
        end

        for j in 2:n
            dp[cur,j] += dp[cur, j-1]
            dp[cur,j] %= MOD
        end

        for j in 1:n
            dp[cur,j] += dp[ant, j]
            dp[cur,j] %= MOD
        end

        ans %= MOD
    end

    println(ans)
end

main()
