#include <bits/stdc++.h>
template <typename T>
void fin(T const& t) {
  std::cout << t << std::endl;
  exit(0);
}
template <int64_t Prime>
struct mod_int {
  int64_t v_;
  mod_int(int64_t x = 0) : v_(x) { normalize(); }
  void normalize() { ((v_ %= Prime) += Prime) %= Prime; }
  mod_int operator+=(mod_int const& r) {
    (v_ += r.v_) %= Prime;
    return *this;
  }
  mod_int operator-=(mod_int const& r) {
    (v_ += Prime - r.v_) %= Prime;
    return *this;
  }
  mod_int operator*=(mod_int const& r) {
    (v_ *= r.v_) %= Prime;
    return *this;
  }
  mod_int operator+(mod_int const& r) {
    mod_int res(*this);
    return res += r;
  }
  mod_int operator-(mod_int const& r) {
    mod_int res(*this);
    return res -= r;
  }
  mod_int operator*(mod_int const& r) {
    mod_int res(*this);
    return res *= r;
  }
  mod_int pow(int x) const {
    int64_t res = 1, v = v_;
    while (x > 0) {
      if (x & 1) (res *= v) %= Prime;
      x /= 2;
      (v *= v) %= Prime;
    }
    return mod_int(res);
  }
  mod_int inv() const { return pow(Prime - 2); }
};
int64_t const MOD = 1e9 + 7;
int main() {
  int N, M;
  std::cin >> N >> M;
  std::vector<int> S(N), T(M);
  for (int i = 0; i < N; ++i) std::cin >> S[i];
  for (int i = 0; i < M; ++i) std::cin >> T[i];
  if (N > M) {
    std::swap(N, M);
    std::swap(S, T);
  }
  std::vector<mod_int<MOD>> t(M + 1, 0);
  t[0] = 1;
  std::vector<std::vector<mod_int<MOD>>> sum(N + 1, t);
  std::fill(sum[0].begin(), sum[0].end(), mod_int<MOD>(1));
  for (int i = 1; i <= N; ++i) {
    for (int j = 0; j < M; ++j) {
      mod_int<MOD> tmp = sum[i][j];
      for (int ii = 0; ii < i; ++ii)
        if (S[ii] == T[j]) {
          tmp += sum[ii][j];
        }
      sum[i][j + 1] = tmp;
    }
  }
  fin(sum[N][M].v_);
  return 0;
}
