#include <bits/stdc++.h>
#define rep(i, n)     for (int i = 0; i < (int)(n); ++i)
#define rep1(i, n)    for (int i = 1; i <= (int)(n); ++i)
#define irep(i, a, n) for (int i = a; i < (int)(n); ++i)
#define rrep(i, n)    for (int i = (int)(n) - 1; i >= 0; --i)
#define rrep1(i, n)   for (int i = (int)(n); i >= 1; --i)
#define allrep(V, v)  for (auto &&V : v)
#define all(x)        (x).begin(), (x).end()
using lint = long long;
constexpr int    INF  = 1 << 30;
constexpr lint   INFL = 1LL << 62;
constexpr int    MOD  = 1e9 + 7;
constexpr double EPS  = 1e-9;
using namespace std;

template <long long mod_num>
class ModInt {
  long long n_;

  public:
  constexpr ModInt(const long long num = 0) : n_(num % mod_num) { }
  constexpr const long long&value() const { return n_; }
  constexpr bool           operator==(const ModInt &r) const { return this->n_ == r.n_; }
  constexpr bool           operator==(const long long &r) const { return this->n_ == r; }
  constexpr bool           operator!=(const ModInt &r) const { return this->n_ != r.n_; }
  constexpr bool           operator!=(const long long &r) const { return this->n_ != r; }
  constexpr bool           operator<(const ModInt &r) const { return this->n_ < r.n_; }
  constexpr bool           operator<(const long long &r) const { return this->n_ < r; }
  constexpr bool           operator>(const ModInt &r) const { return this->n_ > r.n_; }
  constexpr bool           operator>(const long long &r) const { return this->n_ > r; }
  constexpr bool           operator<=(const ModInt &r) const { return this->n_ <= r.n_; }
  constexpr bool           operator<=(const long long &r) const { return this->n_ <= r; }
  constexpr bool           operator>=(const ModInt &r) const { return this->n_ >= r.n_; }
  constexpr bool           operator>=(const long long &r) const { return this->n_ >= r; }
  constexpr ModInt         operator+(const ModInt &r) const { return ModInt(*this) += r; }
  constexpr ModInt         operator-(const ModInt &r) const { return ModInt(*this) -= r; }
  constexpr ModInt         operator*(const ModInt &r) const { return ModInt(*this) *= r; }
  constexpr ModInt         operator/(const ModInt &r) const { return ModInt(*this) /= r; }
  constexpr ModInt         operator+(const long long &r) const { return ModInt(*this) += ModInt(r); }
  constexpr ModInt         operator-(const long long &r) const { return ModInt(*this) -= ModInt(r); }
  constexpr ModInt         operator*(const long long &r) const { return ModInt(*this) *= ModInt(r); }
  constexpr ModInt         operator/(const long long &r) const { return ModInt(*this) /= ModInt(r); }
  friend ModInt            operator+(const long long &l, const ModInt &r) { return ModInt(l) += r; }
  friend ModInt            operator-(const long long &l, const ModInt &r) { return ModInt(l) -= r; }
  friend ModInt            operator*(const long long &l, const ModInt &r) { return ModInt(l) *= r; }
  friend ModInt            operator/(const long long &l, const ModInt &r) { return ModInt(l) /= r; }
  constexpr ModInt         &operator++() { return *this += 1; }
  constexpr ModInt         &operator--() { return *this -= 1; }
  constexpr ModInt         &operator+=(const ModInt &r) {
    n_ += r.n_;
    if (n_ >= mod_num) n_ -= mod_num;
    return *this;
  }
  constexpr ModInt &operator-=(const ModInt &r) {
    if (n_ < r.n_) n_ += mod_num;
    n_ -= r.n_;
    return *this;
  }
  constexpr ModInt &operator*=(const ModInt &r) {
    n_ = n_ * r.n_ % mod_num;
    return *this;
  }
  constexpr ModInt &operator/=(ModInt r) {
    long long exp = mod_num - 2;
    while (exp) {
      if (exp & 2) *this *= r;
      r   *= r;
      exp /= 2;
    }
    return *this;
  }
  friend std::istream &operator>>(std::istream &is, ModInt<mod_num> &r) {
    is >> r.n_;
    r.n_ %= r.mod_num;
    return is;
  }
  friend std::ostream &operator<<(std::ostream &os, const ModInt<mod_num> &r) { return os << r.n_; }
  explicit operator int() const { return n_; }
  explicit operator long long() const { return n_; }
  explicit operator double() const { return n_; }
};

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int n, m;
  cin >> n >> m;
  vector<int> s(n), t(m);
  rep (i, n) cin >> s[i];
  rep (i, m) cin >> t[i];
  using mint = ModInt<MOD>;
  vector<vector<mint>> dp(n + 1, vector<mint>(m + 1, 0));
  rep (i, n + 1) dp[i][0] = 1;
  rep (i, m + 1) dp[0][i] = 1;
  rep1 (i, n) {
    rep1 (j, m) {
      dp[i][j] += dp[i - 1][j];
      dp[i][j] += dp[i][j - 1];
      dp[i][j] -= dp[i - 1][j - 1];
      if (s[i - 1] == t[j - 1]) {
        dp[i][j] += dp[i - 1][j - 1];
      }
    }
  }
  cout << dp[n][m] << endl;
  return 0;
}

Measured memory_bytes: 31616