#include <bits/stdc++.h>
using namespace std;
constexpr long long int MOD = 1000000007;
constexpr long long int SIZE = 2010;
long long int dp[SIZE][SIZE];
void solve() {
  long long int N, M;
  cin >> N >> M;
  vector<long long int> s(N);
  for (auto &x : s) {
    cin >> x;
  }
  vector<long long int> t(M);
  for (auto &x : t) {
    cin >> x;
  }
  for (long long int i = 0; i <= N; i++) {
    dp[i][0] = 1;
  }
  for (long long int i = 0; i <= M; i++) {
    dp[0][i] = 1;
  }
  for (long long int i = 1; i <= N; i++) {
    for (long long int p = 1; p <= M; p++) {
      dp[i][p] = dp[i - 1][p] + dp[i][p - 1] - dp[i - 1][p - 1];
      if (s[i - 1] == t[p - 1]) {
        dp[i][p] += 1;
      }
      dp[i][p] = (dp[i][p] + 10 * MOD) % MOD;
    }
  }
  cout << dp[N][M] << endl;
}
signed main() {
  solve();
  return 0;
}
