#include <bits/stdc++.h>
using namespace std;
const int INF = 1e+9;
const int MOD = 1e+9 + 7;
int main() {
  int N, M;
  cin >> N >> M;
  vector<char> S(2010), T(2010);
  for (long long i = 0; i < (long long)(N); i++) cin >> S[i];
  for (long long i = 0; i < (long long)(M); i++) cin >> T[i];
  vector<vector<long long>> dp(2010, vector<long long>(2010, 0));
  vector<vector<long long>> sum(2010, vector<long long>(2010, 0));
  dp[0][0] = 1;
  sum[1][1] = 1;
  for (long long i = 0; i < (long long)(N + 1); i++) {
    for (long long j = 0; j < (long long)(M + 1); j++) {
      if (i == 0 && j == 0) continue;
      if (i - 1 >= 0 && j - 1 >= 0 && S[i - 1] == T[j - 1]) {
        dp[i][j] = sum[i][j];
      }
      sum[i + 1][j + 1] = (sum[i][j + 1] % MOD + sum[i + 1][j] % MOD -
                           sum[i][j] % MOD + dp[i][j] % MOD);
      while (sum[i + 1][j + 1] < 0) {
        sum[i + 1][j + 1] += MOD;
      }
      sum[i + 1][j + 1] %= MOD;
    }
  }
  cout << sum[N + 1][M + 1] << endl;
}
