#include <bits/stdc++.h>
#include <iostream>
#include <vector>

using namespace std;

int N, M;

int S[2010], T[2010];

long long int dp[2100][2100];
 
int main() {
  
    cin >> N >> M;
  
    for (int i = 0; i < N; ++i) cin >> S[i],dp[i][0] = 1;
  
    for (int i = 0; i < M; ++i) cin >> T[i],dp[0][j] = 1;
 
    memset(dp, 0, sizeof(dp));
  
    dp[0][0] = 1;
  
    for (int i = 0; i <= N; ++i) {
        for (int j = 0; j <= M; ++j) {
          
            if (i > 0 && j > 0 && S[i-1] == T[j-1]) dp[i][j] += dp[i-1][j-1];
                              
            if (i > 0) dp[i][j] += dp[i-1][j];
                 
            if (j > 0) dp[i][j] += dp[i][j-1];        
          
            if (i > 0 && j > 0) dp[i][j] -= dp[i-1][j-1]; 
          
          dp[i][j] %= 1000000007;
        }
    }
  
    cout << dp[N][M] % 1000000007 << endl;
}
