#include <bits/stdc++.h>
using namespace std;
const long long int MOD = 1000000007;
const long long int INF = (long long int)1e15;
long long int S[10000];
long long int T[10000];
long long int dp[2005][2005];
int main() {
  long long int N, M;
  cin >> N >> M;
  for (long long int(i) = (0); (i) < (N); ++(i)) {
    cin >> S[i];
  }
  for (long long int(i) = (0); (i) < (M); ++(i)) {
    cin >> T[i];
  }
  memset(dp, 0, sizeof(dp));
  for (long long int(i) = (0); (i) < (std::max(N, M) + 1); ++(i)) {
    dp[i][0] = dp[0][i] = 1;
  }
  for (long long int(i) = (0); (i) < (N); ++(i)) {
    for (long long int(j) = (0); (j) < (M); ++(j)) {
      dp[i + 1][j + 1] = dp[i][j + 1] + dp[i + 1][j] - dp[i][j];
      if (S[i] == T[j]) {
        dp[i + 1][j + 1] += dp[i][j];
      }
      dp[i + 1][j + 1] %= MOD;
    }
  }
  cout << dp[N][M] << endl;
  return 0;
}
