def CommomSubsequencesCount(s, t): 
  
    n1 = len(s) 
    n2 = len(t) 
    dp = [[0 for i in range(n2 + 1)]  
             for i in range(n1 + 1)] 
  
    for i in range(1, n1 + 1): 
  
        for j in range(1, n2 + 1): 
  
            # if character are same in both  
            # the string 
            if (s[i - 1] == t[j - 1]): 
                dp[i][j] = (1 + dp[i][j - 1] + dp[i - 1][j])% ((10**9) + 7)
            else: 
                dp[i][j] = (dp[i][j - 1] + dp[i - 1][j] -dp[i - 1][j - 1])%((10**9) + 7)          
          
    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()
	print((CommomSubsequencesCount(s,t)+1)%((10**9)+7))