#include <bits/stdc++.h>
using namespace std;
template <class T>
ostream &operator<<(ostream &out, vector<T> const &v) {
  for (auto &&a : v) out << a << " ";
  out << endl;
  return out;
}
template <class T>
void dump(T &a) {
  cout << a << endl;
}
template <class T>
bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
void madd(T &a, T b) {
  a += b;
  a %= 1000000007;
}
template <class T>
void msub(T &a, T b) {
  a -= b;
  if (a < 0) a += 1000000007;
}
void solve() {
  int N, M;
  vector<int> S, T;
  long long dp[2010][2010] = {0};
  long long acc[2010][2010] = {0};
  cin >> N >> M;
  S.resize(N);
  T.resize(M);
  for (int i = 0; i < N; i++) cin >> S[i];
  for (int i = 0; i < M; i++) cin >> T[i];
  long long total = 1;
  for (int n = 0; n < N; n++) {
    int s = S[n];
    for (int m = 0; m < M; m++) {
      int t = T[m];
      if (s != t)
        dp[n][m] = 0;
      else {
        dp[n][m] = 1;
        madd(dp[n][m], acc[n - 1][m - 1]);
      }
      acc[n][m] = dp[n][m];
      if (n > 0) madd(acc[n][m], acc[n - 1][m]);
      if (m > 0) madd(acc[n][m], acc[n][m - 1]);
      if (n > 0 and m > 0) msub(acc[n][m], acc[n - 1][m - 1]);
      madd(total, dp[n][m]);
    }
  }
  cout << total << endl;
}
int main() {
  solve();
  return 0;
}
