#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int N, M;
  cin >> N >> M;
  vector<char> S(N), T(M);
  for (int i = (int)(0); i < (int)(N); i++) cin >> S[i];
  for (int i = (int)(0); i < (int)(M); i++) cin >> T[i];
  vector<vector<ll>> c(N + 10, vector<ll>(M + 10));
  for (int i = (int)(0); i < (int)(N); i++) {
    if (S[i] == T[0]) c[i][0]++;
  }
  for (int i = (int)(0); i < (int)(M); i++) {
    if (S[0] == T[i]) c[0][i]++;
  }
  for (int i = (int)(0); i < (int)(N); i++) {
    for (int j = (int)(0); j < (int)(M); j++) {
      if (S[i + 1] == T[i + 1]) {
        c[i + 1][j + 1] = (2 * c[i][j]) % 1000000007;
      } else {
        c[i + 1][j + 1] = max(c[i][j + 1], c[i + 1][j]) % 1000000007;
      }
    }
  }
  cout << c[N - 1][M - 1] + 2 << endl;
}
