package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(os.Stdout)

	n := getNextInt(scanner)
	m := getNextInt(scanner)

	ss := make([]int, n)
	tt := make([]int, m)

	dp := make([][]int, n+1)

	for i := 0; i < n; i++ {
		dp[i] = make([]int, m+1)
		ss[i] = getNextInt(scanner)
	}
	dp[n] = make([]int, m+1)
	for i := 0; i < m; i++ {
		tt[i] = getNextInt(scanner)
	}
	dp[0][0] = 1
	for i := 0; i <= n; i++ {
		for ii := 0; ii <= m; ii++ {
			if i == 0 || ii == 0 {
				dp[i][ii] = 1
				continue
			}
			dp[i][ii] += dp[i][ii-1]
			dp[i][ii] += dp[i-1][ii]
			if ss[i-1] != tt[ii-1] {
				dp[i][ii] -= dp[i-1][ii-1]
			}

			dp[i][ii] %= 1000000007
		}
	}
	fmt.Fprintln(writer, dp[n][m])

	writer.Flush()
}
