#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9;
const long long MOD = 1000000007;
struct mint {
  long long x;
  mint(long long x = 0) : x((x + MOD) % MOD) {}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= MOD) x %= MOD;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res += a;
  }
  mint& operator-=(const mint a) {
    if ((x += MOD - a.x) >= MOD) x %= MOD;
    return *this;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res -= a;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= MOD;
    return *this;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res *= a;
  }
  mint pow(long long t) const {
    if (!t) {
      return 1;
    }
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1) a *= *this;
    return a;
  }
  mint inv() const { return pow(MOD - 2); }
  mint& operator/=(const mint a) { return (*this) *= a.inv(); }
  mint operator/(const mint a) const {
    mint res(*this);
    return res /= a;
  }
};
mint dp0[2005][2005];
mint dp1[2005][2005];
int main(int argc, char** argv) {
  long long N, M;
  cin >> N >> M;
  vector<long long> S(N + 1);
  vector<long long> T(M + 1);
  for (int i = 0; i < N; ++i) {
    cin >> S[i];
  }
  for (int i = 0; i < M; ++i) {
    cin >> T[i];
  }
  dp0[0][0] = 1;
  for (int i = 0; i < N + 1; ++i)
    for (int j = 0; j < M + 1; ++j) {
      dp0[i + 1][j + 1] += dp0[i][j + 1];
      dp1[i][j] += dp0[i][j];
      dp1[i + 1][j + 1] += dp1[i + 1][j];
      if (S[i] == T[j]) {
        dp0[i + 1][j + 1] += dp1[i][j];
      }
    }
  mint ans = dp1[N][M];
  cout << ans.x << endl;
}
