#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  vector<int> S(n), T(m);
  for (int i = 0; i < n; i++) {
    scanf("%s", &S[i]);
  }
  for (int i = 0; i < m; i++) {
    scanf("%s", &T[i]);
  }
  vector<int> dp(m), ndp(m);
  for (int i = 0; i < n; i++) {
    int sum = 0;
    ndp = dp;
    for (int j = 0; j < m; j++) {
      if (S[i] != T[j]) {
        ndp[j] += sum;
        ndp[j] %= mod;
        continue;
      }
      sum += 1 + (j > 0 ? dp[j - 1] : 0);
      sum %= mod;
      ndp[j] += sum;
      ndp[j] %= mod;
    }
    ndp.swap(dp);
  }
  long long ans = 1 + dp[m - 1];
  ans %= mod;
  ans += mod;
  ans %= mod;
  printf("%lld\n", ans);
  return 0;
}
