import scala.annotation.tailrec
import scala.collection.mutable
import scala.io.StdIn._
object Main extends App {

  val mod = 1000000007L

  val Array(n, m) = readLine.trim.split(' ').map(_.toInt)
  val sList = readLine.trim.split(' ').map(_.toInt).toList
  val tList = readLine.trim.split(' ').map(_.toInt).toList
  val memo = mutable.Map[(Int, Int), Long]()
  println(
    search(sList, tList)
  )

  def search(s: List[Int], t: List[Int], sPos: Int = 0, tPos: Int = 0): Long = {
    memo.getOrElseUpdate((sPos, tPos), {
      (s, t) match {
        case (Nil, _) | (_, Nil) ⇒ 1L
        case (sh::st, th::tt) if sh == th ⇒ (search(st, t, sPos + 1, tPos) + search(s, tt, sPos, tPos + 1)) % mod
        case (_::st, _::tt) ⇒ (search(st, t, sPos + 1, tPos) + search(s, tt, sPos, tPos + 1) - search(st, tt, sPos + 1, tPos + 1)) % mod
      }
    })
  }



  implicit class Scope[T](val receiver: T) extends AnyVal {
    def let[A](@inline func: T ⇒ A): A = func(receiver)
    def tap(@inline func: T ⇒ Unit): T = {
      func(receiver)
      receiver
    }
  }
}