#include <bits/stdc++.h>
using namespace std;
const int mod = (int)1e9 + 7;
const int N = 2005;
int n, m;
int dp[N][N];
int main() {
  cin >> n >> m;
  string a, b;
  a += "@";
  b += "@";
  for (int i = 0; i < n; i++) {
    char c;
    cin >> c;
    a += c;
  }
  for (int i = 0; i < m; i++) {
    char c;
    cin >> c;
    b += c;
  }
  for (int i = 0; i <= n; i++) dp[i][0] = 1;
  for (int i = 0; i <= m; i++) dp[0][i] = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      dp[i][j] = (dp[i][j] - dp[i - 1][j - 1]) % mod;
      dp[i][j] = (dp[i][j] + dp[i - 1][j]) % mod;
      dp[i][j] = (dp[i][j] + dp[i][j - 1]) % mod;
      dp[i][j] %= mod;
      dp[i][j] += mod;
      dp[i][j] %= mod;
      if (a[i] == b[j]) {
        dp[i][j] = (dp[i][j] + dp[i - 1][j - 1]) % mod;
      }
    }
  }
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= m; j++) {
    }
  }
  cout << dp[n][m] << endl;
  return 0;
}
