#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <class T>
void print_container(T &container, string delim = " ") {
  bool first = true;
  for (auto &t : container) {
    if (!first) {
      cout << delim;
    }
    first = false;
    cout << t;
  }
  cout << endl;
}
const int MOD = 1e9 + 7;
int main() {
  int n, m;
  cin >> n >> m;
  vector<ll> s(n), t(m);
  for (int((i)) = (0); ((i)) < ((n)); ((i))++) {
    cin >> s[i];
  }
  for (int((i)) = (0); ((i)) < ((m)); ((i))++) {
    cin >> t[i];
  }
  vector<vector<ll>> dp(n + 1, vector<ll>(m + 1, 0));
  for (int(i) = (0); (i) <= (n); (i)++) {
    dp[i][0] = dp[0][i] = 1;
  }
  for (int(i) = (1); (i) <= (n); (i)++) {
    map<int, ll> accum;
    for (int(j) = (1); (j) <= (m); (j)++) {
      dp[i][j] = dp[i - 1][j];
      accum[t[j - 1]] = (accum[t[j - 1]] + dp[i - 1][j - 1]) % MOD;
      dp[i][j] = (dp[i][j] + accum[s[i - 1]]) % MOD;
    }
  }
  cout << dp[n][m] << endl;
  return 0;
}
