parseInt(x) = parse(Int,x)

parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    mod = 10^9 + 7
    N, M = readline() |> split |> parseMap
    S = readline() |> split |> parseMap
    T = readline() |> split |> parseMap
    DP = [[1 for j in 1:N+1] for i in 1:M+1]
    for i in 1:M
        for j in 1:N
            if T[i]==S[j]
                DP[i+1][j+1] = (DP[i+1][j]+DP[i][j+1])%mod
            else
                DP[i+1][j+1] = (DP[i+1][j]+DP[i][j+1]-DP[i][j])%mod
            end
        end
    end
    print(DP[M+1][N+1])
end

main()