#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int a, b;
  long long ans = 1;
  cin >> a >> b;
  vector<char> s(a), t(b);
  map<string, int> m, mm;
  string p;
  vector<long long> q(a), w(b);
  for (int i = 0; i < a; i++) {
    cin >> s.at(i);
    q.at(i) = 0;
  }
  for (int i = 0; i < b; i++) {
    cin >> t.at(i);
    w.at(i) = 0;
  }
  for (int i = a - 1; i > -1; i--) {
    int p = 0;
    for (int j = b - 1; j > -1; j--) {
      int y = w.at(j);
      if (s.at(i) == t.at(j)) {
        int pp = 0;
        if (p == 0)
          pp = 1;
        else
          pp = p + 1;
        ans = (ans + pp) % 1000000007;
        w.at(j) = (pp + w.at(j)) % 1000000007;
      }
      p = (p + y) % 1000000007;
    }
  }
  cout << ans << endl;
}
