#include <bits/stdc++.h>
void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << std::endl;
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
using ll = long long;
using namespace std;
template <int Mod>
class ModInt {
 public:
  ModInt() : n_(0) {}
  ModInt(long long n) : n_(n % Mod) {
    if (n_ < 0) {
      n_ += Mod;
    }
  }
  ModInt& operator+=(const ModInt& m) {
    n_ += m.n_;
    if (n_ >= Mod) {
      n_ -= Mod;
    }
    return *this;
  }
  ModInt& operator++() { return (*this) += 1; }
  ModInt& operator-=(const ModInt& m) {
    n_ -= m.n_;
    if (n_ < 0) {
      n_ += Mod;
    }
    return *this;
  }
  ModInt& operator--() { return (*this) -= 1; }
  ModInt& operator*=(const ModInt& m) {
    n_ *= m.n_;
    n_ %= Mod;
    return *this;
  }
  ModInt& operator/=(const ModInt& m) {
    *this *= m.Inv();
    return *this;
  }
  ModInt operator+(const ModInt& m) const { return ModInt(*this) += m; }
  ModInt operator-(const ModInt& m) const { return ModInt(*this) -= m; }
  ModInt operator*(const ModInt& m) const { return ModInt(*this) *= m; }
  ModInt operator/(const ModInt& m) const { return ModInt(*this) /= m; }
  bool operator!=(const ModInt& m) const { return n_ != m.n_; }
  bool operator<(const ModInt& m) const { return n_ < m.n_; }
  bool operator<=(const ModInt& m) const { return n_ <= m.n_; }
  bool operator==(const ModInt& m) const { return n_ == m.n_; }
  bool operator>(const ModInt& m) const { return n_ > m.n_; }
  bool operator>=(const ModInt& m) const { return n_ >= m.n_; }
  ModInt operator-() const { return ModInt(-n_); }
  ModInt Pow(int n) const {
    if (n < 0) {
      return Inv().Pow(-n);
    }
    ModInt a = 1, b = *this;
    while (n != 0) {
      if (n & 1) {
        a *= b;
      }
      n /= 2;
      b *= b;
    }
    return a;
  }
  ModInt Inv() const { return Pow(Mod - 2); }
  long long value() const { return n_; }
  static ModInt Fact(int n) {
    for (int i = fact_.size(); i <= n; ++i) {
      fact_.push_back(i == 0 ? 1 : fact_.back() * i);
    }
    return fact_[n];
  }
  static ModInt Comb(int n, int k) { return Perm(n, k) / Fact(k); }
  static ModInt CombSlow(int n, int k) { return PermSlow(n, k) / Fact(k); }
  static ModInt Perm(int n, int k) { return Fact(n) / Fact(n - k); }
  static ModInt PermSlow(int n, int k) {
    ModInt p = 1;
    for (int i = 0; i < k; ++i) {
      p *= (n - i);
    }
    return p;
  }

 private:
  long long n_;
  static std::vector<ModInt> fact_;
};
template <int Mod>
std::vector<ModInt<Mod>> ModInt<Mod>::fact_;
template <int Mod>
std::ostream& operator<<(std::ostream& out, const ModInt<Mod>& m) {
  out << m.value();
  return out;
}
using mint = ModInt<1000000007>;
int main() {
  int n, m;
  read_from_cin(n, m);
  ;
  vector<int> s(n);
  for (int i = 0; i < (int)(n); ++i) cin >> s[i];
  vector<int> t(m);
  for (int i = 0; i < (int)(m); ++i) cin >> t[i];
  vector<vector<mint>> dp(n + 1, vector<mint>(m + 1));
  for (int i = 0; i < (int)(n + 1); ++i) dp[i][0] = 1;
  for (int i = 0; i < (int)(m + 1); ++i) dp[0][i] = 1;
  for (int i = 0; i < (int)(n); ++i)
    for (int j = 0; j < (int)(m); ++j) {
      dp[i + 1][j + 1] = dp[i + 1][j] + dp[i][j + 1] - dp[i][j];
      if (s[i] == t[j]) dp[i + 1][j + 1] += dp[i][j];
    }
  for (int i = 0; i < (int)(n + 1); ++i) {
    for (int j = 0; j < (int)(m + 1); ++j) cerr << dp[i][j] << " ";
    cerr << endl;
  }
  write_to_cout(dp[n][m]);
  ;
}
