package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

const (
	mod = int64(1000000007)
)

func main() {
	var n, m int
	fmt.Scan(&n)
	fmt.Scan(&m)

	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)

	s := make([]int, n)
	for i := 0; i < n; i++ {
		scanner.Scan()
		s[i], _ = strconv.Atoi(scanner.Text())
	}
	t := make([]int, m)
	for i := 0; i < m; i++ {
		scanner.Scan()
		t[i], _ = strconv.Atoi(scanner.Text())
	}

	dp := make([][]int64, n+1)
	for i := 0; i <= n; i++ {
		dp[i] = make([]int64, m+1)
		for j := 0; j <= m; j++ {
			if i == 0 || j == 0 {
				dp[i][j] = 1
				continue
			}
			ret := dp[i][j-1]

			for k := i; k > 0; k-- {
				if s[k-1] == t[j-1] {
					ret = (ret + dp[k-1][j-1]) % mod
				}
			}

			dp[i][j] = ret
		}
	}

	fmt.Println(dp[n][m])
}
