#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[]) {
  long long int N, M;
  std::cin >> N >> M;
  std::vector<long long int> S(N), T(M);
  std::vector<std::vector<long long int> > dp = vector<vector<long long int> >(
                                               N + 1,
                                               vector<long long int>(M + 1, 0)),
                                           dpsum =
                                               vector<vector<long long int> >(
                                                   N + 1, vector<long long int>(
                                                              M + 1, 0));
  for (int i = 0; i < N; i++) std::cin >> S[i];
  for (int i = 0; i < M; i++) std::cin >> T[i];
  for (int i = 1; i < N + 1; i++) {
    for (int j = 1; j < M + 1; j++) {
      if (S[i - 1] == T[j - 1]) {
        dp[i][j] = dpsum[i - 1][j - 1] + 1;
      } else {
        dp[i][j] = 0;
      }
      dpsum[i][j] =
          (dpsum[i - 1][j] + dpsum[i][j - 1] - dpsum[i - 1][j - 1] + dp[i][j]) %
          1000000007;
    }
  }
  std::cout << dpsum[N][M] + 1 << '\n';
  return 0;
}
