#include <bits/stdc++.h>
using namespace std;
int slen, tlen;
string s, t;
int dp[7007][7007];
int main() {
  cin >> slen >> tlen;
  for (int i = 1; i <= slen; i++) {
    cin >> s[i];
  }
  for (int i = 1; i <= tlen; i++) {
    cin >> t[i];
  }
  for (int i = 1; i <= slen; i++) {
    for (int j = 1; j <= tlen; j++) {
      dp[i][j] = dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1];
      if (s[i] == t[j]) {
        dp[i][j] += dp[i - 1][j - 1] + 1;
        dp[i][j] %= 1000000007;
      }
    }
  }
  cout << (dp[slen][tlen] + 1) % 1000000007;
}
