def CommomSubsequencesCount(s, t): 
  
    n1 = len(s) 
    n2 = len(t)
    dp=[[0 for i in range(n2+1)] for j in range(n1+1)] ; h= int(1e9+7)
    for i in range(1, n1 + 1): 
        for j in range(1, n2 + 1): 
            if (s[i - 1] == t[j - 1]): 
                dp[i][j] = (1 + dp[i][j - 1] + dp[i - 1][j])% h
            else: 
                dp[i][j] = (dp[i][j - 1] + dp[i - 1][j] -dp[i - 1][j - 1])% h         
          
    return dp[n1][n2]

ll= lambda : list(map(int,input().split()))
testcases=1
# testcases=int(input())
for testcase in range(testcases):
	[n,m]=ll()
	s=ll()
	t=ll()
	h= int(1e9+7)
	print((CommomSubsequencesCount(s,t)+1)%h)