#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 7;
const long long longinf = 1LL << 60;
const long long mod = 1e9 + 7;
long long dp[2010][2010];
char s[2010], t[2010];
int n, m;
void solve() {
  for (int i = (int)0; i < (int)(n + 1); ++i) dp[i][0] = 1;
  for (int j = (int)0; j < (int)(m + 1); ++j) dp[0][j] = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % mod;
      dp[i][j] %= mod;
      if (s[i] == t[j]) {
        dp[i][j] += dp[i - 1][j - 1];
        dp[i][j] %= mod;
      }
      dp[i][j] += mod - dp[i - 1][j - 1];
      dp[i][j] %= mod;
    }
  }
}
int main() {
  cin >> n >> m;
  for (int i = (int)0; i < (int)(n); ++i) cin >> s[i + 1];
  for (int i = (int)0; i < (int)(m); ++i) cin >> t[i + 1];
  solve();
  cout << dp[n][m] << endl;
  return 0;
}
