package main

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

var sc *bufio.Scanner

const BufferSize = 1024

func nextInt() int {
	if !sc.Scan() {
		panic(nil)
	}
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

var production bool

func debugf(format string, v ...interface{}) {
	if !production {
		fmt.Printf(format, v...)
	}
}

const MOD = 1000000000 + 7

func seek(s *[]int, t *[]int, c *[][]int, i int, j int) int {
	ans := 0
	if (*c)[i][j] >= 0 {
		return (*c)[i][j]
	}

	for k := i + 1; k < len(*s); k++ {
		for l := j + 1; l < len(*t); l++ {
			if (*s)[k] == (*t)[l] {
				ans++
				ans %= MOD
				ans += seek(s, t, c, k, l)
				ans %= MOD
			}
		}
	}
	(*c)[i][j] = ans
	//debugf("i: %d, j: %d, ans: %d\n", i, j, ans)
	return ans
}

func answer(reader io.Reader, writer io.Writer) {
	sc = bufio.NewScanner(reader)
	buf := make([]byte, BufferSize)
	sc.Buffer(buf, 1e+6)
	sc.Split(bufio.ScanWords)
	n := nextInt()
	m := nextInt()
	s := make([]int, n)
	t := make([]int, m)
	c := make([][]int, n)

	for i := range s {
		s[i] = nextInt()
		c[i] = make([]int, m)
		for j := range t {
			c[i][j] = -1
		}
	}
	for i := range t {
		t[i] = nextInt()
	}

	ans := 1
	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			if s[i] == t[j] {
				ans++
				ans %= MOD
				ans += seek(&s, &t, &c, i, j)
				ans %= MOD
			}
		}
	}

	_, _ = fmt.Fprintf(writer, "%d", ans)
}

func main() {
	production = true
	answer(os.Stdin, os.Stdout)
}
