#!/usr/local/bin/python3

n, m = map(int, input().split())
s = list(map(int, input().split()))
t = list(map(int, input().split()))

dp = [[0 for y in range(m + 1)] for x in range(n + 1)]
con = [[0 for y in range(m)] for x in range(n)]

MOD = 1000000007

dp[0][0] = 1
for i in range(1, n + 1):
	dp[i][0] = 1
	if s[i - 1] == t[0]:
		dp[i][1] = 2

for j in range(1, m + 1):
	dp[0][j] = 1
	if t[j - 1] == s[0]:
		dp[1][j] = 2

for i in range(n):
	for j in range(m):
		if s[i] == t[j]:
			con[i][j] = 1

for x in range(1, n + 1):
	for y in range(1, m + 1):
		tmp = 0
		for k in range(y - 1):
			if con[x - 1][k] > 0:
				tmp = tmp + dp[x - 1][k]
		for l in range(x - 1):
			if con[l][y - 1] > 0:
				tmp = tmp + dp[l][y - 1]
		tmp = tmp + dp[x - 1][y - 1]
		if con[x - 1][y - 1] > 0:
			tmp = tmp + dp[x - 1][y - 1]
		dp[x][y] = tmp % MOD

print(dp[n][m])
