#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
const long long INF = 1e18;
template <typename T>
T pow(T a, long long n, T e = 1) {
  T ret = e;
  while (n) {
    if (n & 1) ret *= a;
    a *= a;
    n >>= 1;
  }
  return ret;
}
template <long long mod>
struct ModInt {
  long long x;
  ModInt() : x(0) {}
  ModInt(long long x_) {
    if ((x = x_ % mod + mod) >= mod) x -= mod;
  }
  ModInt& operator+=(ModInt rhs) {
    if ((x += rhs.x) >= mod) x -= mod;
    return *this;
  }
  ModInt& operator-=(ModInt rhs) {
    if ((x -= rhs.x) < 0) x += mod;
    return *this;
  }
  ModInt& operator*=(ModInt rhs) {
    x = (unsigned long long)x * rhs.x % mod;
    return *this;
  }
  ModInt& operator/=(ModInt rhs) {
    x = (unsigned long long)x * rhs.inv().x % mod;
    return *this;
  }
  ModInt operator-() const { return -x < 0 ? mod - x : -x; }
  ModInt operator+(ModInt rhs) const { return ModInt(*this) += rhs; }
  ModInt operator-(ModInt rhs) const { return ModInt(*this) -= rhs; }
  ModInt operator*(ModInt rhs) const { return ModInt(*this) *= rhs; }
  ModInt operator/(ModInt rhs) const { return ModInt(*this) /= rhs; }
  bool operator==(ModInt rhs) const { return x == rhs.x; }
  bool operator!=(ModInt rhs) const { return x != rhs.x; }
  ModInt inv() const { return pow(*this, mod - 2); }
  friend ostream& operator<<(ostream& s, ModInt<mod> a) {
    s << a.x;
    return s;
  }
  friend istream& operator>>(istream& s, ModInt<mod>& a) {
    s >> a.x;
    return s;
  }
};
using mint = ModInt<1000000007>;
mint dp[2001][2001];
signed main() {
  long long n, m;
  cin >> n >> m;
  long long s[n], t[m];
  for (long long i = (0); i < (n); ++i) cin >> s[i];
  for (long long i = (0); i < (m); ++i) cin >> t[i];
  dp[0][0] = 1;
  for (long long i = (0); i < (n + 1); ++i)
    for (long long j = (0); j < (m + 1); ++j) {
      if (i > 0) dp[i][j] += dp[i - 1][j];
      if (j > 0) dp[i][j] += dp[i][j - 1];
      if (i > 0 and j > 0 and s[i - 1] != s[j - 1])
        dp[i][j] -= dp[i - 1][j - 1];
    }
  cout << dp[n][m] << endl;
}
