import sys
input=sys.stdin.readline
from collections import deque
from heapq import heappush,heappop
import re

def int_raw():
    return int(input())
 
def ss_raw():
    return input().split()
 
def ints_raw():
    return tuple(map(int, ss_raw()))


def mod_inv(a, b):
    r = a
    w = b
    u = 1
    v = 0
    while w != 0:
        t = r//w
        r -= t*w
        r, w = w, r
        u -= t*v
        u, v = v, u
    return (u % b+b) % b


DIV = 10**9+7

def ncr(n, r, mod=DIV):
	r = min(r, n-r)
	ret = 1
	for i in range(1, r+1):
		ret = ret * (n-i+1) % mod
		ret = ret * mod_inv(i, mod) % mod
	return ret


def main():
    ans =0
    N,M= ints_raw()
    Ss = ints_raw()
    Ts = ints_raw()

    """Ls =[]
    l=0
    for a in As:
        l+=a
        Ls.append(l)"""
    dp = [[0]*M for _ in range(N)]
    dp[0][0]=1 if Ss[0]!=Ts[0] else 2
    for idx in range(1,N):
        dp[idx][0] = dp[idx-1][0] if Ss[idx] != Ts[0] else dp[idx-1][0]+1

    for midx in range(1, M):
        dp[0][midx] = dp[0][midx-1] if Ss[0] != Ts[midx] else dp[0][midx-1]+1

    for m in range(1,M):
        for n in range(1,N):
            dp[n][m] = dp[n][m-1]+dp[n-1][m]-dp[n-1][m-1]
            if Ss[n] ==Ts[m]:
                dp[n][m] += dp[n-1][m-1]
                dp[n][m] = dp[n][m]%DIV

    return dp[-1][-1]

print(main())
