#include <bits/stdc++.h>
constexpr long long MOD = 1000000007;
int main() {
  int N, M;
  std::cin >> N >> M;
  std::vector<long long> S(N), T(M);
  for (auto& val : S) std::cin >> val;
  for (auto& val : T) std::cin >> val;
  std::vector<std::vector<long long>> dp(N, std::vector<long long>(M, 0));
  std::vector<std::vector<long long>> acc(N, std::vector<long long>(M, 0));
  dp[0][0] = S[0] == T[0] ? 1 : 0;
  acc[0][0] = dp[0][0] + 1;
  for (int i = 1; i < N; ++i) {
    dp[i][0] = S[i] == T[0] ? 1 : 0;
    acc[i][0] = acc[i - 1][0] + dp[i][0];
  }
  for (int j = 1; j < M; ++j) {
    dp[0][j] = S[0] == T[j] ? 1 : 0;
    acc[0][j] = acc[0][j - 1] + dp[0][j];
  }
  for (int i = 1; i < N; ++i) {
    for (int j = 1; j < M; ++j) {
      if (S[i] == T[j]) {
        dp[i][j] = acc[i - 1][j - 1];
        acc[i][j] = (acc[i][j - 1] + acc[i - 1][j]) % MOD;
      } else {
        dp[i][j] = 0;
        acc[i][j] = (acc[i][j - 1] + (acc[i - 1][j] - acc[i - 1][j - 1])) % MOD;
      }
    }
  }
  std::cout << acc.back().back() << std::endl;
  return 0;
}
