import algorithm, future, hashes, macros, math, sequtils, sets, strutils, tables, times, unicode, queues
 
macro unpack(rhs: seq, cnt: static[int]): auto =
  let t = genSym(); result = quote do:(let `t` = `rhs`;())
  if NimMinor <= 17:
    for i in 0..<cnt: result[0][1].add(quote do:`t`[`i`])
  else:
    for i in 0..<cnt: result[1].add(quote do:`t`[`i`])
 
template input(T: typedesc, cnt: Natural = 1): untyped =
  let line = stdin.readLine.split(" ")
  when T is int:         line.map(parseInt).unpack(cnt)
  elif T is float:       line.map(parseFloat).unpack(cnt)
  elif T is string:      line.unpack(cnt)
  elif T is char:        line.mapIt(it[0]).unpack(cnt)
  elif T is seq[int]:    line.map(parseInt)
  elif T is seq[float]:  line.map(parseFloat)
  elif T is seq[string]: line
  elif T is seq[char]:   line.mapIt(it[0])
 
proc `%=`(n: var int, m: int)  = n = n mod m
# proc `//=`(n: var int, m: int) = n = n div m
# proc `<<=`(n: var int, m: int) = n = n shl m
# proc `>>=`(n: var int, m: int) = n = n shr m
# proc `<?=`(n: var int, m: int) = n = min(n, m)
# proc `>?=`(n: var int, m: int) = n = max(n, m)
# proc newSeq2[T](n1, n2: Natural): seq[seq[T]] = newSeqWith(n1, newSeq[T](n2))
# proc newSeq3[T](n1, n2, n3: Natural): seq[seq[seq[T]]] = newSeqWith(n1, newSeqWith(n2, newSeq[T](n3)))
 
# -------------------------------------------------- #


const MOD = 1000000007

var (sl, tl) = input(int,2)
var ss = input(seq[int])
var ts = input(seq[int])

var dp = newSeqWith(sl+1, newSeq[int](tl+1))
for i in 0..sl:
  dp[i][0]=1
for j in 0..tl:
  dp[0][j]=1

for x in 0..sl+tl-2:
  for i in 0..sl-1:
    var j = x-i
    if j<0: continue
    if j>tl-1: continue
    var s = ss[i]
    var t = ts[j]
    dp[i+1][j+1] = dp[i+1][j] + dp[i][j+1] - dp[i][j]
    if s==t:
      dp[i+1][j+1] += dp[i][j]
    dp[i+1][j+1] %= MOD

#echo dp
echo dp[sl][tl]