#include <bits/stdc++.h> 
using namespace std; 

using strings = vector<int>;
const int MOD = (int)1e9 + 7;
  
// return the number of common subsequence in 
// two strings 
int CommomSubsequencesCount(strings s, strings t) 
{ 
    int n1 = s.size(); 
    int n2 = t.size(); 
    int dp[n1+1][n2+1]; 
  
    for (int i = 0; i <= n1; i++) { 
        for (int j = 0; j <= n2; j++) { 
            dp[i][j] = 0; 
        } 
    } 
  
    // for each character of S 
    for (int i = 1; i <= n1; i++) { 
  
        // for each charcater in T 
        for (int j = 1; j <= n2; j++) { 
  
            // 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];             
            else 
                dp[i][j] = dp[i][j - 1] + dp[i - 1][j] -  
                                        dp[i - 1][j - 1];       
          dp[i][j] %= MOD;
        } 
    } 
  
    return dp[n1][n2]; 
} 
  
// Driver Program 
int main() 
{ 
  int N, M;
  cin >> N >> M;
    strings s; 
  s.resize(N);
  for (int i = 0; i < N; ++i) cin >> s[i];
    strings t;
  t.resize(M);
  for (int i = 0; i < M; ++i) cin >> t[i];
  
    cout << (CommomSubsequencesCount(s, t) + 1) % MOD << endl; 
    return 0; 
} 