#include <bits/stdc++.h>
using namespace std;
using Int = long long;
constexpr Int MOD = 1e9 + 7;
Int dp[2001][2001];
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> S(N), T(M);
  for (auto &s : S) cin >> s;
  for (auto &t : T) cin >> t;
  map<int, vector<int>> MT;
  for (int i = 0; i < M; i++) {
    MT[T[i]].push_back(i + 1);
  }
  for (int i = 0; i <= 2000; i++) {
    dp[0][i] = dp[i][0] = 1;
  }
  for (int i = 1; i <= N; i++) {
    map<int, vector<Int>> MT_S;
    for (auto &p : MT) {
      auto &v = MT_S[p.first];
      v.push_back(0);
      for (auto x : p.second) {
        v.push_back(dp[i - 1][x - 1]);
      }
      for (int i = 1; i < v.size(); i++) {
        (v[i] += v[i - 1]) %= MOD;
      }
    }
    for (int j = 1; j <= M; j++) {
      dp[i][j] = dp[i - 1][j];
      auto &v = MT[S[i - 1]];
      auto k = upper_bound(begin(v), end(v), j) - begin(v);
      (dp[i][j] += MT_S[S[i - 1]][k]) %= MOD;
    }
  }
  cout << dp[N][M] << '\n';
  return 0;
}
