#include <bits/stdc++.h>
using namespace std;
constexpr long long MOD = 1e9 + 7;
constexpr int INF = 1 << 30;
constexpr long long LINF = 1LL << 60;
template <typename T>
T chmin(T& a, T b) {
  if (a > b) {
    a = b;
  }
  return a;
}
template <typename T>
T chmax(T& a, T b) {
  if (a < b) {
    a = b;
  }
  return a;
}
void addmod(long long& a, long long b) { a = (a + b) % MOD; }
template <typename T>
void dumpContents(const T& v, const string& msg) {
  cerr << "### " << msg << " ###\n";
  for (const auto& x : v) {
    cerr << x << " ";
  }
  cerr << endl;
}
struct before_main_function {
  before_main_function() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(20) << fixed;
  }
} before_main_function;
constexpr int N_MAX = 2000 + 1;
long long dp[N_MAX][N_MAX] = {0};
int main(int argc, char** argv) {
  int N, M;
  cin >> N >> M;
  vector<int> S(N);
  for (int i = 0; i < N; i++) {
    cin >> S[i];
  }
  vector<int> T(M);
  vector<vector<int> > RT(1e5 + 1);
  for (int i = 0; i < M; i++) {
    cin >> T[i];
    RT[T[i]].emplace_back(i);
  }
  if (S[0] == T[0]) {
    dp[0][0] = 1;
  }
  for (int i = 0; i < N - 1; i++) {
    int s = S[i + 1];
    for (int j = 0; j < M; j++) {
      const vector<int>& tmp = RT[s];
      if (tmp.empty()) continue;
      auto it = lower_bound(begin(tmp), end(tmp), j + 1);
      for (; it != end(tmp); it++) {
        addmod(dp[i + 1][*it], dp[i][j] + 1);
      }
    }
  }
  long long ret = 1;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++) {
      addmod(ret, dp[i][j]);
    }
  }
  cout << ret << "\n";
  return 0;
}
