#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
long long dp[2020][2020];
long long sum[2020][2020];
int main() {
  long long N, M;
  cin >> N >> M;
  vector<string> S(N + 1), T(M + 1);
  for (int i = 0; i < N; ++i) cin >> S[i];
  for (int i = 0; i < M; ++i) cin >> T[i];
  long long ans = 0;
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < M; ++j) {
      if (S[i] == T[j])
        dp[i + 1][j + 1] = (sum[i][j] + 1) % mod;
      else
        dp[i + 1][j + 1] = 0;
      sum[i + 1][j + 1] =
          (sum[i][j + 1] + sum[i + 1][j] - sum[i][j] + dp[i + 1][j + 1]) % mod;
      ans += dp[i + 1][j + 1];
      ans %= mod;
    }
  }
  cout << (ans + 1) % mod << endl;
}
