#include <bits/stdc++.h>
using namespace std;
long long MOD = 1000000007;
void cout_vec(vector<long long> &vec) {
  for (int i = 0; i < vec.size(); i++) {
    if (i != 0) {
      cout << ' ';
    }
    cout << vec[i];
  }
  cout << endl;
}
int main() {
  int N, M;
  cin >> N >> M;
  vector<string> S(N + 1, "");
  vector<string> T(M + 1, "");
  for (int i = 1; i <= N; i++) {
    cin >> S[i];
  }
  for (int i = 1; i <= M; i++) {
    cin >> T[i];
  }
  vector<long long> prev(M + 1, 1);
  for (int i = 1; i <= N; i++) {
    long long tmp = 1;
    long long tmp0 = 1;
    for (int j = 1; j <= M; j++) {
      tmp0 = prev[j];
      if (S[i] == T[j]) {
        prev[j] = (prev[j - 1] + prev[j]) % MOD;
      } else {
        prev[j] = prev[j - 1] - tmp + prev[j];
      }
      tmp = tmp0;
    }
  }
  cout << prev[M] << endl;
}
