N, M = map(int, input().split())
S = list(map(int, input().split()))
T = list(map(int, input().split()))
mod = 10 ** 9 + 7
W = [1] * (N + 1)
for i, t in enumerate(T):
	W2 = W[:]
	k = 0
	for j, s in enumerate(S):
		if t == s:
			k += W[j]
		W2[j + 1] = (W[j + 1] + k) % mod
	W = W2
print(W[-1]) N, M = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M S = list(map(int, input().split())) S list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split T = list(map(int, input().split())) T list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split mod = 10 ** 9 + 7 mod 10 ** 9 + 7 10 ** 9 10 9 7 W = [1] * (N + 1) W [1] * (N + 1) [1] 1 N + 1 N 1 for i, t in enumerate(T):
	W2 = W[:]
	k = 0
	for j, s in enumerate(S):
		if t == s:
			k += W[j]
		W2[j + 1] = (W[j + 1] + k) % mod
	W = W2 i t enumerate(T) enumerate T W2 = W[:] W2 W[:] W : k = 0 k 0 for j, s in enumerate(S):
		if t == s:
			k += W[j]
		W2[j + 1] = (W[j + 1] + k) % mod
	 j s enumerate(S) enumerate S if t == s:
			k += W[j]
		 t == s t s k += W[j] k W[j] W j W2[j + 1] = (W[j + 1] + k) % mod W2[j + 1] W2 j + 1 j 1 (W[j + 1] + k) % mod W[j + 1] + k W[j + 1] W j + 1 j 1 k mod W = W2 W W2 print(W[-1]) print W[-1] W -1 k += W[j] W[j] k M = map(int, input().split()) map(int, input().split()) M k = 0 0 k N, M = map(int, input().split()) map(int, input().split()) N W2 = W[:] W[:] W2 S = list(map(int, input().split())) list(map(int, input().split())) S T = list(map(int, input().split())) list(map(int, input().split())) T W = W2 W2 W mod = 10 ** 9 + 7 10 ** 9 + 7 mod W = [1] * (N + 1) [1] * (N + 1) W
N, M = map(int, input().split())
S = list(map(int, input().split()))
T = list(map(int, input().split()))
mod = 10 ** 9 + 7
W = [1] * (N + 1)
for i, t in enumerate(T):
	W2 = W[:]
	k = 0
	for j, s in enumerate(S):
		if t == s:
			k += W[j]
		W2[j + 1] = (W[j + 1] + k) % mod
	W = W2
print(W[-1])