#include <bits/stdc++.h>
using namespace std;
struct init {
  init() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);
  };
} aaaaaaa;
long long int mod = 1e9 + 7;
int main() {
  long long int n, m;
  cin >> n >> m;
  vector<int> s(n);
  vector<int> t(m);
  for (auto i = 0; i < (n); i++) cin >> s[i];
  for (auto i = 0; i < (m); i++) cin >> t[i];
  vector<vector<long long int>> dp(n + 1, vector<long long int>(m + 1, 0));
  for (auto i = 0; i < (n + 1); i++) dp[i][0] = 1;
  for (auto i = 0; i < (m + 1); i++) dp[0][i] = 1;
  for (auto i = 1; i <= (n); i++) {
    for (auto j = 1; j <= (m); j++) {
      if (t[i - 1] == s[j - 1]) {
        dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
      } else {
        dp[i][j] = dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1];
      }
      dp[i][j] = (dp[i][j] + mod) % mod;
    }
  }
  cout << dp[n][m] << endl;
  return 0;
}
