#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
long long fast_exp(long long a, long long b) {
  if (b == 0)
    return 1;
  else {
    long long res = 1;
    res = fast_exp(a, b / 2);
    res = (res * res) % mod;
    if (b % 2 == 1) res = (res * a) % mod;
    return res;
  }
}
const long long N = 1e6;
long long n, m;
string s, t;
long long dp[3000][3000] = {};
bool vis[3000][3000] = {};
long long num_common(long long first, long long second) {
  if (first == -1 || second == -1) {
    return 1;
  } else if (vis[first][second] == 1) {
    return dp[first][second];
  } else {
    long long ways = 0;
    ways = (ways + num_common(first - 1, second)) % mod;
    ways = (ways + num_common(first, second - 1)) % mod;
    ways = (ways - num_common(first - 1, second - 1) + mod) % mod;
    if (s[first] == t[second]) {
      ways = (ways + num_common(first - 1, second - 1)) % mod;
    }
    dp[first][second] = ways;
    vis[first][second] = 1;
    return dp[first][second];
  }
}
int main() {
  cin >> n >> m;
  for (long long i = 0; i < n; i++) cin >> s[i];
  for (long long j = 0; j < m; j++) cin >> t[j];
  vis[0][0] = 1;
  dp[0][0] = 1;
  if (s[0] == t[0]) dp[0][0]++;
  cout << num_common(n - 1, m - 1) << endl;
  return 0;
}
