#include <bits/stdc++.h>
constexpr long long int MOD = 1000000007L;
long long int right(const std::vector<int>& s_series,
                    const std::vector<int>& t_series, const int si,
                    const int ti,
                    std::vector<std::vector<long long int>>& memo) {
  if (si >= s_series.size() || ti >= t_series.size()) {
    return 1;
  } else if (memo[si][ti] >= 0) {
    return memo[si][ti];
  } else {
    memo[si][ti] = right(s_series, t_series, si + 1, ti + 1, memo);
    for (auto tn = ti; tn < t_series.size(); ++tn) {
      if (s_series[si] == t_series[tn]) {
        memo[si][ti] += right(s_series, t_series, si + 1, tn + 1, memo);
        memo[si][ti] %= MOD;
      }
    }
    for (auto sn = si + 1; sn < s_series.size(); ++sn) {
      if (s_series[sn] == t_series[ti]) {
        memo[si][ti] += right(s_series, t_series, sn + 1, ti + 1, memo);
        memo[si][ti] %= MOD;
      }
    }
    return memo[si][ti];
  }
}
int main() {
  int n, m;
  std::cin >> n >> m;
  std::vector<int> s_nums(n), t_nums(m);
  for (auto& s : s_nums) std::cin >> s;
  for (auto& t : t_nums) std::cin >> t;
  std::vector<std::vector<long long int>> memo(
      n, std::vector<long long int>(m, -1));
  std::cout << right(s_nums, t_nums, 0, 0, memo) << std::endl;
}
