N, M = gets.split.map(&:to_i)
S = gets.split.map(&:to_i)
T = gets.split.map(&:to_i)

dp = Array.new(N+2){Array.new(M+2, 0)}
dp[0][0] = 1
MOD = 10**9+7
(N+1).times do |i|
    (M+1).times do |j|
        dp[i][j] += dp[i-1][j] + dp[i][j-1]
        dp[i][j] -= dp[i-1][j-1] if S[i-1] != T[j-1]
        dp[i][j] %= MOD
    end
end
puts dp[N][M]