#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using Graph = vector<vi>;
using P = pair<int, int>;
const int INFTY = 1e9 + 7;
int main() {
  int N, M;
  cin >> N >> M;
  vi S(N), T(M);
  for (int i = 0; i < (int)(N); i++) cin >> S[i];
  for (int j = 0; j < (int)(M); j++) cin >> T[j];
  map<int, vi> pos_S, pos_T;
  for (int j = 0; j < (int)(M); j++) pos_T[T[j]].push_back(j + 1);
  Graph dp(N + 1, vi(M + 1));
  for (int i = 0; i < (int)(N + 1); i++) dp[i][0] = 1;
  for (int j = 0; j < (int)(M + 1); j++) dp[0][j] = 1;
  for (int i = 1; i <= N; i++) {
    for (int j = 1; j <= M; j++) {
      dp[i][j] = dp[i - 1][j];
      if (pos_T.count(S[i - 1])) {
        for (auto p : pos_T.at(S[i - 1])) {
          if (p > j) continue;
          dp[i][j] += dp[i - 1][p - 1];
          dp[i][j] %= INFTY;
        }
      }
    }
  }
  cout << dp[N][M] << endl;
  return 0;
}
