#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, "0"), T(M + 1, "0");
  for (int i = 1; i < N + 1; ++i) cin >> S[i];
  for (int i = 1; i < M + 1; ++i) cin >> T[i];
  for (int i = 0; i < N + 1; ++i) {
    sum[i][0] = 1;
    dp[i][0] = 1;
  }
  for (int i = 0; i < M + 1; ++i) {
    sum[0][i] = 1;
    dp[0][i] = 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] % mod;
      else
        dp[i][j] = 0;
      sum[i][j] = (sum[i - 1][j] % mod + sum[i][j - 1] % mod -
                   sum[i - 1][j - 1] % mod + dp[i][j] % mod) %
                  mod;
    }
  }
  cout << sum[N][M] << endl;
}
