#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const long long INF = 1e+14;
const long double eps = 1e-8;
const long double pi = acos(-1.0);
void Yes() {
  cout << "Yes" << endl;
  exit(0);
}
void No() {
  cout << "No" << endl;
  exit(0);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, M;
  cin >> N >> M;
  char S[2020], T[2020];
  for (int i = 0; i < N; i++) cin >> S[i];
  for (int i = 0; i < M; i++) cin >> T[i];
  long long dp[2020][2020], sdp[2020][2020];
  memset(dp, 0, sizeof(dp));
  memset(sdp, 0, sizeof(sdp));
  dp[0][0] = 1LL;
  sdp[1][1] = 1LL;
  for (int i = 0; i <= N; i++) {
    for (int j = 0; j <= M; j++) {
      if (i == 0 && j == 0) continue;
      if (i - 1 >= 0 && j - 1 >= 0 && S[i - 1] == T[j - 1]) {
        dp[i][j] = sdp[i][j];
      }
      sdp[i + 1][j + 1] = sdp[i][j + 1] + sdp[i + 1][j] - sdp[i][j] + dp[i][j];
      sdp[i + 1][j + 1] = (sdp[i + 1][j + 1] % mod + mod) % mod;
    }
  }
  cout << sdp[N + 1][M + 1] << endl;
  return 0;
}
