#include <bits/stdc++.h>
int main() {
  int N, M;
  std::cin >> N >> M;
  std::vector<int> S_arr(N), T_arr(M);
  for (int i = 0; i < N; i++) {
    std::cin >> S_arr[i];
  }
  for (int i = 0; i < M; i++) {
    std::cin >> T_arr[i];
  }
  std::vector<int> dp((N + 1) * (M + 1));
  for (int n = 0; n < N + 1; n++) {
    dp[n * (M + 1)] = 1;
  }
  for (int m = 0; m < M + 1; m++) {
    dp[m] = 1;
  }
  int mod = 1000000007;
  for (int n = 0; n < N; n++) {
    const auto s = S_arr[n];
    for (int m = 0; m < M; m++) {
      const auto t = T_arr[m];
      if (s == t) {
        dp[(n + 1) * (M + 1) + m + 1] =
            (dp[(n + 1) * (M + 1) + m] + dp[n * (M + 1) + m + 1]) % mod;
      } else {
        dp[(n + 1) * (M + 1) + m + 1] =
            (dp[(n + 1) * (M + 1) + m] + dp[n * (M + 1) + m + 1] -
             dp[n * (M + 1) + m]) %
            mod;
      }
    }
  }
  std::cout << dp[(N + 1) * (M + 1) - 1] << std::endl;
}
