import java.io._
import java.util.StringTokenizer
import scala.util.control.Breaks.{breakable,break}

object Main extends App {
  val in = new InputReader(System.in)
  val pw = new PrintWriter(System.out)


  val MOD = 1e9.toLong + 7
  val N, M = in.next().toInt
  val S = new Array[Int](N+1)
  val T = new Array[Int](M+1)
  for (i <- 1 to N)
    S(i) = in.next().toInt
  for (i <- 1 to M)
    T(i) = in.next().toInt

  //
  val imos = Array.ofDim[Long](N+1, M+1)
  val dp = Array.ofDim[Long](N+1, M+1)
  for (n <- 1 to N) {
    for (m <- 1 to M) {
      if (S(n) == T(m)) {
        dp(n)(m) = imos(n-1)(m-1) + 1
        dp(n)(m) %= MOD
      }

      imos(n)(m) = imos(n-1)(m) + imos(n)(m-1) - imos(n-1)(m-1)
      imos(n)(m) %= MOD
      imos(n)(m) += dp(n)(m)
      imos(n)(m) %= MOD
    }
  }


  var ans = 0L
  for (n <- 1 to N)
    for (m <- 1 to M) {
      ans += dp(n)(m)
      ans %= MOD
    }

  println((ans + 1) % MOD)
}


class InputReader(stream: InputStream) {
  private val reader = new BufferedReader(new InputStreamReader(stream))
  private var tokenizer: StringTokenizer = new StringTokenizer(reader.readLine())
  def next(): String = {
    while (!tokenizer.hasMoreTokens()) {
      tokenizer = new StringTokenizer(reader.readLine())
    }
    tokenizer.nextToken()
  }
}
