#include <bits/stdc++.h>
std::istream& operator>>(std::istream& input, __int128_t& value) {
  long long tmp;
  input >> tmp;
  value = tmp;
  return input;
}
std::ostream& operator<<(std::ostream& output, const __int128_t value) {
  output << (long long)value;
  return output;
}
const int MAX_N = 2010;
const int MOD = 1e9 + 7;
__int128_t N, M;
__int128_t S[MAX_N], T[MAX_N];
__int128_t dp[MAX_N][MAX_N] = {};
__int128_t dp_sum[MAX_N][MAX_N] = {};
int main(int argc, char** argv) {
  std::cin >> N >> M;
  for (int i = 1; i <= N; i++) {
    std::cin >> S[i];
  }
  for (int i = 1; i <= M; i++) {
    std::cin >> T[i];
  }
  __int128_t ret = 1;
  for (int i = 1; i <= N; i++) {
    for (int j = 1; j <= M; j++) {
      if (S[i] == T[j]) {
        dp[i][j] = (dp_sum[i - 1][j - 1] + 1) % MOD;
      } else {
        dp[i][j] = 0;
      }
      dp_sum[i][j] = (dp_sum[i - 1][j] + dp_sum[i][j - 1] -
                      dp_sum[i - 1][j - 1] + dp[i][j]) %
                     MOD;
      ret = (ret + dp[i][j]) % MOD;
    }
  }
  std::cout << ret << std::endl;
  return 0;
}
