#include <bits/stdc++.h>
template <typename InputIterator>
typename InputIterator::value_type summation(InputIterator first,
                                             InputIterator last) {
  return std::accumulate(first, last, typename InputIterator::value_type());
}
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v);
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p);
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v) {
  for (auto &i : v) {
    stream >> i;
  }
  return stream;
}
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p) {
  stream >> p.first >> p.second;
  return stream;
}
int main() {
  int64_t n, m;
  std::cin >> n >> m;
  std::vector<int64_t> s(n), t(m);
  std::cin >> s >> t;
  std::vector<std::set<int64_t>> p(n);
  for (int64_t i = 0; i < n; i++) {
    for (int64_t j = 0; j < m; j++) {
      if (s[i] == t[j]) {
        p[i].insert(j);
      }
    }
  }
  std::vector<int64_t> ans(n, 0), ans_sum(n + 1, 1);
  constexpr int64_t mod = 1000000007;
  for (int64_t i = 0; i < n; i++) {
    for (const auto j : p[i]) {
      ans[j] += ans_sum[j];
      ans[j] %= mod;
    }
    ans_sum[0] = 1;
    for (int64_t i = 1; i <= n; i++) {
      ans_sum[i] = ans_sum[i - 1] + ans[i - 1];
      ans_sum[i] %= mod;
    }
  }
  std::cout << ans_sum.back() << std::endl;
  return 0;
}
