import collections
n,m = map(int, raw_input().split(' '))
s,t = map(int, raw_input().split(' ')), map(int, raw_input().split(' '))
dp,prefix = [[0 for j in range(len(t))] for i in range(len(s))], [[0 for j in range(len(t))] for i in range(len(s))]
total = 1
mod = (10 ** 9) + 7
for ii in range(len(s)):
	for jj in range(len(t)):
		if s[ii] == t[jj]:
			dp[ii][jj] = 1+ (prefix[ii-1][jj-1] if ii-1>=0 and jj-1>=0 else 0)
			total += dp[ii][jj]
			total %= mod
		prefix[ii][jj] += prefix[ii - 1][jj] if ii - 1 >=0 else 0
		prefix[ii][jj] += prefix[ii][jj - 1] if jj - 1 >=0 else 0
		prefix[ii][jj] -= prefix[ii - 1][jj - 1] if (jj - 1 >=0) and (ii-1) >=0 else 0
		prefix[ii][jj] += dp[ii][jj]
		prefix[ii][jj] %= mod
		
print total import collections collections n,m = map(int, raw_input().split(' ')) n map(int, raw_input().split(' ')) map int raw_input().split(' ') ().split () raw_input split ' ' m s,t = map(int, raw_input().split(' ')), map(int, raw_input().split(' ')) s map(int, raw_input().split(' ')) map int raw_input().split(' ') ().split () raw_input split ' ' t map(int, raw_input().split(' ')) map int raw_input().split(' ') ().split () raw_input split ' ' [0 for j in range(len(t))] for i in range(len(s)) for i in range(len(s)) i range(len(s)) range len(s) len s for i in range(len(s)) [0 for j in range(len(t))] dp,prefix = [[0 for j in range(len(t))] for i in range(len(s))], [[0 for j in range(len(t))] for i in range(len(s))] dp [[0 for j in range(len(t))] for i in range(len(s))] prefix [[0 for j in range(len(t))] for i in range(len(s))] total = 1 total 1 mod = (10 ** 9) + 7 mod (10 ** 9) + 7 10 ** 9 10 9 7 for ii in range(len(s)):
	for jj in range(len(t)):
		if s[ii] == t[jj]:
			dp[ii][jj] = 1+ (prefix[ii-1][jj-1] if ii-1>=0 and jj-1>=0 else 0)
			total += dp[ii][jj]
			total %= mod
		prefix[ii][jj] += prefix[ii - 1][jj] if ii - 1 >=0 else 0
		prefix[ii][jj] += prefix[ii][jj - 1] if jj - 1 >=0 else 0
		prefix[ii][jj] -= prefix[ii - 1][jj - 1] if (jj - 1 >=0) and (ii-1) >=0 else 0
		prefix[ii][jj] += dp[ii][jj]
		prefix[ii][jj] %= mod
		 ii range(len(s)) range len(s) len s for jj in range(len(t)):
		if s[ii] == t[jj]:
			dp[ii][jj] = 1+ (prefix[ii-1][jj-1] if ii-1>=0 and jj-1>=0 else 0)
			total += dp[ii][jj]
			total %= mod
		prefix[ii][jj] += prefix[ii - 1][jj] if ii - 1 >=0 else 0
		prefix[ii][jj] += prefix[ii][jj - 1] if jj - 1 >=0 else 0
		prefix[ii][jj] -= prefix[ii - 1][jj - 1] if (jj - 1 >=0) and (ii-1) >=0 else 0
		prefix[ii][jj] += dp[ii][jj]
		prefix[ii][jj] %= mod
		 jj range(len(t)) range len(t) len t if s[ii] == t[jj]:
			dp[ii][jj] = 1+ (prefix[ii-1][jj-1] if ii-1>=0 and jj-1>=0 else 0)
			total += dp[ii][jj]
			total %= mod
		 s[ii] == t[jj] s[ii] s ii t[jj] t jj dp[ii][jj] = 1+ (prefix[ii-1][jj-1] if ii-1>=0 and jj-1>=0 else 0) dp[ii][jj] [ii] dp ii jj 1+ (prefix[ii-1][jj-1] if ii-1>=0 and jj-1>=0 else 0) 1 prefix[ii-1][jj-1] if ii-1>=0 and jj-1>=0 else 0 ii-1>=0 and jj-1>=0 ii-1>=0 ii-1 ii 1 0 jj-1>=0 jj-1 jj 1 0 prefix[ii-1][jj-1] [ii-1] prefix ii-1 ii 1 jj-1 jj 1 0 total += dp[ii][jj] total dp[ii][jj] [ii] dp ii jj total %= mod total mod prefix[ii][jj] += prefix[ii - 1][jj] if ii - 1 >=0 else 0 prefix[ii][jj] [ii] prefix ii jj prefix[ii - 1][jj] if ii - 1 >=0 else 0 ii - 1 >=0 ii - 1 ii 1 0 prefix[ii - 1][jj] [ii - 1] prefix ii - 1 ii 1 jj 0 prefix[ii][jj] += prefix[ii][jj - 1] if jj - 1 >=0 else 0 prefix[ii][jj] [ii] prefix ii jj prefix[ii][jj - 1] if jj - 1 >=0 else 0 jj - 1 >=0 jj - 1 jj 1 0 prefix[ii][jj - 1] [ii] prefix ii jj - 1 jj 1 0 prefix[ii][jj] -= prefix[ii - 1][jj - 1] if (jj - 1 >=0) and (ii-1) >=0 else 0 prefix[ii][jj] [ii] prefix ii jj prefix[ii - 1][jj - 1] if (jj - 1 >=0) and (ii-1) >=0 else 0 (jj - 1 >=0) and (ii-1) >=0 jj - 1 >=0 jj - 1 jj 1 0 (ii-1) >=0 ii-1 ii 1 0 prefix[ii - 1][jj - 1] [ii - 1] prefix ii - 1 ii 1 jj - 1 jj 1 0 prefix[ii][jj] += dp[ii][jj] prefix[ii][jj] [ii] prefix ii jj dp[ii][jj] [ii] dp ii jj prefix[ii][jj] %= mod prefix[ii][jj] [ii] prefix ii jj mod print t = map(int, raw_input().split(' ')), map(int, raw_input().split(' ')) map(int, raw_input().split(' ')) t n,m = map(int, raw_input().split(' ')) map(int, raw_input().split(' ')) n prefix = [[0 for j in range(len(t))] for i in range(len(s))], [[0 for j in range(len(t))] for i in range(len(s))] [[0 for j in range(len(t))] for i in range(len(s))] prefix dp,prefix = [[0 for j in range(len(t))] for i in range(len(s))], [[0 for j in range(len(t))] for i in range(len(s))] [[0 for j in range(len(t))] for i in range(len(s))] dp total = 1 1 total total %= mod mod total total += dp[ii][jj] dp[ii][jj] total m = map(int, raw_input().split(' ')) map(int, raw_input().split(' ')) m s,t = map(int, raw_input().split(' ')), map(int, raw_input().split(' ')) map(int, raw_input().split(' ')) s mod = (10 ** 9) + 7 (10 ** 9) + 7 mod
import collections
n,m = map(int, raw_input().split(' '))
s,t = map(int, raw_input().split(' ')), map(int, raw_input().split(' '))
dp,prefix = [[0 for j in range(len(t))] for i in range(len(s))], [[0 for j in range(len(t))] for i in range(len(s))]
total = 1
mod = (10 ** 9) + 7
for ii in range(len(s)):
	for jj in range(len(t)):
		if s[ii] == t[jj]:
			dp[ii][jj] = 1+ (prefix[ii-1][jj-1] if ii-1>=0 and jj-1>=0 else 0)
			total += dp[ii][jj]
			total %= mod
		prefix[ii][jj] += prefix[ii - 1][jj] if ii - 1 >=0 else 0
		prefix[ii][jj] += prefix[ii][jj - 1] if jj - 1 >=0 else 0
		prefix[ii][jj] -= prefix[ii - 1][jj - 1] if (jj - 1 >=0) and (ii-1) >=0 else 0
		prefix[ii][jj] += dp[ii][jj]
		prefix[ii][jj] %= mod
		
print total
