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