#include <bits/stdc++.h>
template <typename t>
inline t add(t x, t y) {
  return (x + y) % 1000000007;
}
template <typename t>
inline t mult(t x, t y) {
  return (x * y) % 1000000007;
}
int main(void) {
  int n, m;
  std::cin >> n >> m;
  std::vector<std::vector<long long int> > dp(
      n + 2, std::vector<long long int>(m + 2));
  std::vector<std::vector<long long int> > sum(
      n + 2, std::vector<long long int>(m + 2));
  std::vector<int> s(n + 1);
  for (int i = 1; i <= n; i++) {
    std::cin >> s[i];
  }
  std::vector<int> t(m + 1);
  for (int i = 1; i <= m; i++) {
    std::cin >> t[i];
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      dp[i][j] = (s[i] == t[j]) ? sum[i - 1][j - 1] + 1 : 0;
      sum[i][j] = sum[i - 1][j] + dp[i][j] + sum[i][j - 1] - sum[i - 1][j - 1];
      sum[i][j] = sum[i][j] % 1000000007;
    }
  }
  std::cout << sum[n][m] + 1 << std::endl;
  return 0;
}
