#include <bits/stdc++.h>
int main(int argc, char** argv) {
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);
  std::cout << std::fixed << std::setprecision(6);
  std::cerr << std::fixed << std::setprecision(6);
  int N, M;
  std::cin >> N >> M;
  std::vector<int> S(N), T(M);
  for (auto& i : S) std::cin >> i;
  for (auto& i : T) std::cin >> i;
  std::vector<std::map<int, std::vector<int>>> G(N);
  for (int i = 0; i < N; i++)
    for (int j = i + 1; j < N; j++) G[i][S[j]].push_back(j);
  long long dp[2][2222], *curr = dp[0], *next = dp[1];
  memset(curr, 0, sizeof(dp[0]));
  for (int i = 0; i < M; i++) {
    memcpy(next, curr, sizeof(dp[0]));
    int x = T[i];
    for (int j = 0; j < N; j++)
      if (S[j] == x) (next[j] += 1) %= 1000000007;
    for (int j = 0; j < N; j++) {
      const auto& map = G[j];
      if (map.count(x))
        for (const auto& k : map.at(x)) (next[k] += curr[j]) %= 1000000007;
    }
    std::swap(curr, next);
  }
  long long s = 1;
  for (int i = 0; i < N; i++) (s += curr[i]) %= 1000000007;
  std::cout << s << std::endl;
  return 0;
}
