#include <bits/stdc++.h>
using namespace std;
long long ccs(string s, string t) {
  long long n1 = s.length();
  long long n2 = t.length();
  long long p[n1 + 1][n2 + 1];
  for (long long i = 0; i <= n1; i++) {
    for (long long j = 0; j <= n2; j++) {
      p[i][j] = 0;
    }
  }
  for (long long i = 1; i <= n1; i++) {
    for (long long j = 1; j <= n2; j++) {
      if (s[i - 1] == t[j - 1])
        p[i][j] = (1 + p[i][j - 1] + p[i - 1][j]) % 1000000007;
      else
        p[i][j] = (p[i][j - 1] + p[i - 1][j] - p[i - 1][j - 1]) % 1000000007;
    }
  }
  return (1 + p[n1][n2]) % 1000000007;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n, m;
  cin >> n >> m;
  string a = "", b = "";
  for (long long x = 0; x < n; x++) {
    char c;
    cin >> c;
    a = a + c;
  }
  for (long long x = 0; x < m; x++) {
    char c;
    cin >> c;
    b = b + c;
  }
  cout << ccs(a, b);
  return 0;
}
