# util functions

# debug
$debugFlag = ( ARGV[0] != nil )
p "==== DEBUG MODE ====" if $debugFlag

def pd(str)
  p str if $debugFlag
end

def printd(str)
  print str if $debugFlag
end

# input
inputs = []
lc = 0
while l = $stdin.gets do
  if false
    inputs << l.chomp.split(" ").map(&:to_s)
  else
    inputs << l.chomp.split(" ").map(&:to_i)
  end
  lc += 1
end

nn = inputs[0][0]
mm = inputs[0][1]
ss = inputs[1]
ts = inputs[2]

# input check
if $debugFlag
  p "--- INPUT (begin) ---"
  inputs.each do |l_i|
    p l_i
  end
  p "--- INPUT (end) ---"
  print "\n"
end

# body
if $debugFlag
  p nn
  p mm
  p ss
  p ts
end

dp = []
for i in 0..nn
  tmp = []
  for j in 0..mm
    if i == 0 or j == 0
      tmp[j] = 0
    elsif ss[i-1] == ts[j-1]
      tmp[j] = dp[i-1][j] + tmp[j-1] + 1
    else # ss[i] != ts[j]
      tmp[j] = dp[i-1][j] + tmp[j-1] - dp[i-1][j-1]
    end
  end
  dp << tmp
end


if $debugFlag
  dp.each do |dp_i|
    p dp_i
  end
end

puts (dp[nn][mm] + 1)%(10**9+7)
