#include <bits/stdc++.h>
using namespace std;
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
inline long long toLL(string s) {
  long long v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}
const int mod = 1000000007;
struct mint {
  long long x;
  mint() : x(0) {}
  mint(long long x) : x((x % mod + mod) % mod) {}
  mint& fix() {
    x = (x % mod + mod) % mod;
    return *this;
  }
  mint operator-() const { return mint(0) - *this; }
  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; }
  bool operator<(const mint& a) const { return x < a.x; }
  bool operator==(const mint& a) const { return x == a.x; }
};
istream& operator>>(istream& i, mint& a) {
  i >> a.x;
  return i;
}
ostream& operator<<(ostream& o, const mint& a) {
  o << a.x;
  return o;
}
mint dp0[2005][2005];
mint dp1[2005][2005];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n, m;
  cin >> n >> m;
  vector<int> s(n + 1), t(m + 1);
  for (long long i = 0; i < (long long)(n); i++) cin >> s[i];
  for (long long i = 0; i < (long long)(m); i++) cin >> t[i];
  dp0[0][0] = 1;
  for (long long i = 0; i < (long long)(n + 1); i++)
    for (long long j = 0; j < (long long)(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] += dp1[i][j];
    }
  cout << dp1[n][m] << endl;
  return 0;
}
