local mce, mfl, msq, mmi, mma = math.ceil, math.floor, math.sqrt, math.min, math.max
local n, m = io.read("*n", "*n", "*l")
local s, t = {}, {}
local str = io.read()
local ti = 0
local mod = 1000000007
for v in str:gmatch("%d+") do
  ti = ti + 1
  s[ti] = tonumber(v)
end
ti = 0
str = io.read()
for v in str:gmatch("%d+") do
  ti = ti + 1
  t[ti] = tonumber(v)
end
local cnt, sum = {}, {}
for i = 1, n * m do
  cnt[i], sum[i] = 0, 0
end
-- m = 1
if s[1] == t[1] then cnt[1] = 1 end
sum[1] = cnt[1]
for i = 2, n do
  if s[i] == t[1] then
    cnt[i] = 1
  end
  sum[i] = cnt[i] + sum[i - 1]
end

for i_m = 2, m do
  if s[1] == t[i_m] then
    cnt[n * (i_m - 1) + 1] = 1
  end
  sum[n * (i_m - 1) + 1] = (sum[n * (i_m - 2) + 1] + cnt[n * (i_m - 1) + 1]) % mod
  for i_n = 2, n do
    local pos = n * (i_m - 1) + i_n
    if s[i_n] == t[i_m] then
      cnt[pos] = sum[pos - n - 1] + 1
    end
    sum[pos] = (cnt[pos] + sum[pos - n] + sum[pos - 1] - sum[pos - n - 1]) % mod
  end
end
local ret = (sum[n * m] + 1) % mod
print(ret)
