#include <bits/stdc++.h>
using namespace std;
constexpr long long INF = 1e16;
constexpr long long MOD = 1000000007;
long long max(long long a, long long b) { return a < b ? b : a; }
long long min(long long a, long long b) { return a > b ? b : a; }
double maxf(double a, double b) { return a < b ? b : a; }
template <typename T>
inline string toString(const T &a) {
  ostringstream oss;
  oss << a;
  return oss.str();
}
long long accdp[2001][2001];
int main() {
  long long N, M;
  cin >> N >> M;
  vector<long long> S(N);
  vector<long long> T(M);
  for (long long i = 0; i < (N); ++i) cin >> S[i];
  for (long long i = 0; i < (M); ++i) cin >> T[i];
  for (long long i = 0; i < (N); ++i) {
    for (long long j = 0; j < (M); ++j) {
      accdp[i + 1][j + 1] =
          ((accdp[i][j + 1] + accdp[i + 1][j] - accdp[i][j]) % MOD +
           (S[i] == T[j] ? (accdp[i][j] + 1) : 0)) %
          MOD;
    }
  }
  cout << (accdp[N][M] + 1) % MOD << endl;
}
