import strutils,sequtils
import algorithm,sets,lists,critbits,sequtils,queues,intsets,strutils,tables,math

const DIVIEND = 10^9 + 7

let read = iterator: string {.closure.} =
  while true:
    for s in stdin.readLine.split:
      yield s


let
  n, m = read().parseInt
  si = stdin.readLine.split.map parseInt
  ti = stdin.readLine.split.map parseInt
var
  dp = newSeq[seq[int]](n+1)
  dp_sum = newSeq[seq[int]](n+1)
dp.fill(newSeq[int](m+1))
dp_sum.fill(newSeq[int](m+1))

for i in 0..<n:
  for j in 0..<m:
    if si[i] == ti[j]:
      dp[i+1][j+1] = (1 + dp_sum[i][j]) mod DIVIEND
    dp_sum[i+1][j] = (dp_sum[i][j] + dp_sum[i+1][max(j-1, 0)] - dp_sum[i][max(j-1, 0)] + dp[i+1][j]) mod DIVIEND
    dp_sum[i][j+1] = (dp_sum[max(i-1, 0)][j+1] + dp_sum[i][j] - dp_sum[max(i-1, 0)][j] + dp[i][j+1]) mod DIVIEND
    dp_sum[i+1][j+1] = (dp_sum[i][j+1] + dp_sum[i+1][j] - dp_sum[i][j] + dp[i+1][j+1]) mod DIVIEND

echo ((dp_sum[n][m] + 1) mod DIVIEND)
