#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
long long dp[3003][3003];
int main() {
  int n, m;
  string s, t;
  cin >> n >> m >> s >> t;
  s = "$" + s, t = "#" + t;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      if (s[i] == t[j])
        dp[i][j] = dp[i - 1][j - 1] + 1;
      else
        dp[i][j] = dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1];
      dp[i][j] %= mod;
    }
  }
  long long sum = 1;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      if (s[i] == t[j]) sum += dp[i][j];
      sum %= mod;
    }
  }
  cout << sum;
}
