package main

import (
  "fmt"
)

func main() {
  var N, M int
  fmt.Scan(&N, &M)
  S := make([]int, N)
  T := make([]int, M)
  p := 1000000007
  var x int
  for i := 0; i < N; i++ {
    fmt.Scan(&x)
    S[i] = x
  }
  for i := 0; i < M; i++ {
    fmt.Scan(&x)
    T[i] = x
  }
  DP := make([][]int, N + 1)
  for i := 0; i < N + 1; i++ {
    DP[i] = make([]int, M + 1)
  }
  for i := 0; i < N + 1; i++ {
    DP[i][0] = 1
  }
  for j := 0; j < M + 1; j++ {
    DP[0][j] = 1
  }
  for i := 0; i < N; i++ {
    for j := 0; j < M; j++ {
      DP[i + 1][j + 1] = DP[i][j + 1] + DP[i + 1][j] - DP[i][j]
      if S[i] == T[j] {
        DP[i + 1][j + 1] += DP[i][j]
      }
      DP[i + 1][j + 1] %= p
    }
  }
  fmt.Println(DP[N][M])
}