#include <bits/stdc++.h>
using namespace std;
int POWINT(int x, int n) {
  int ret = 1;
  for (int i = (int)0; i < (int)n; i++) ret *= x;
  return ret;
};
long long POWLL(long long x, int n) {
  long long ret = 1;
  for (int i = (int)0; i < (int)n; i++) ret *= x;
  return ret;
};
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
};
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
};
const int mod = 1e9 + 7;
struct mint {
  long long x;
  mint(long long x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod - a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const { return mint(*this) += a; }
  mint operator-(const mint a) const { return mint(*this) -= a; }
  mint operator*(const mint a) const { return mint(*this) *= 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 { return mint(*this) /= a; }
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }
mint dp0[2005][2005];
mint dp1[2005][2005];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  vector<int> s(n + 1), t(m + 1);
  for (int i = (int)0; i < (int)n; i++) {
    cin >> s[i];
  }
  for (int i = (int)0; i < (int)m; i++) {
    cin >> t[i];
  }
  dp0[0][0] = 1;
  for (int i = (int)0; i < (int)n + 1; i++) {
    for (int j = (int)0; j < (int)m + 1; j++) {
      dp0[i + 1][j] += dp0[i][j];
      dp1[i][j] += dp0[i][j];
      dp1[i][j + 1] += dp1[i][j];
      if (s[i] == t[j]) {
        dp0[i + 1][j + 1] += dp1[i][j];
      }
    }
  }
  mint ans = dp1[n][m];
  cout << ans << endl;
  return 0;
};
