#include <bits/stdc++.h>
using namespace std;
using vint = vector<long long>;
using pint = pair<long long, long long>;
using vpint = vector<pint>;
template <typename A, typename B>
inline void chmin(A& a, B b) {
  if (a > b) a = b;
}
template <typename A, typename B>
inline void chmax(A& a, B b) {
  if (a < b) a = b;
}
template <class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>& p) {
  ost << "{" << p.first << "," << p.second << "}";
  return ost;
}
template <class T>
ostream& operator<<(ostream& ost, const vector<T>& v) {
  ost << "{";
  for (long long i = 0; i < v.size(); i++) {
    if (i) ost << ",";
    ost << v[i];
  }
  ost << "}";
  return ost;
}
template <uint32_t mod>
struct ModInt {
  uint32_t a;
  ModInt& s(uint32_t vv) {
    a = vv < mod ? vv : vv - mod;
    return *this;
  }
  ModInt(int64_t x = 0) { s(x % mod + mod); }
  ModInt& operator+=(const ModInt& x) { return s(a + x.a); }
  ModInt& operator-=(const ModInt& x) { return s(a + mod - x.a); }
  ModInt& operator*=(const ModInt& x) {
    a = uint64_t(a) * x.a % mod;
    return *this;
  }
  ModInt& operator/=(const ModInt& x) {
    *this *= x.inv();
    return *this;
  }
  ModInt operator+(const ModInt& x) const { return ModInt(*this) += x; }
  ModInt operator-(const ModInt& x) const { return ModInt(*this) -= x; }
  ModInt operator*(const ModInt& x) const { return ModInt(*this) *= x; }
  ModInt operator/(const ModInt& x) const { return ModInt(*this) /= x; }
  bool operator==(const ModInt& x) const { return a == x.a; }
  bool operator!=(const ModInt& x) const { return a != x.a; }
  bool operator<(const ModInt& x) const { return a < x.a; }
  ModInt operator-() const { return ModInt() - *this; }
  ModInt pow(int64_t n) const {
    ModInt res(1), x(*this);
    while (n) {
      if (n & 1) res *= x;
      x *= x;
      n >>= 1;
    }
    return res;
  }
  ModInt inv() const { return pow(mod - 2); }
};
template <uint32_t mod>
istream& operator>>(istream& in, ModInt<mod>& a) {
  return (in >> a.a);
}
template <uint32_t mod>
ostream& operator<<(ostream& out, const ModInt<mod>& a) {
  return (out << a.a);
}
using mint = ModInt<1000000007>;
long long N, M;
long long S[2222], T[2222];
mint dp[2222][2222][2];
signed main() {
  cin >> N >> 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][0] = 1;
  for (long long i = 0; i < (N + 1); i++)
    for (long long j = 0; j < (N + 1); j++) {
      if (i + 1 <= N) dp[i + 1][j][0] += dp[i][j][0];
      dp[i][j][1] += dp[i][j][0];
      if (j + 1 <= M) dp[i][j + 1][1] += dp[i][j][1];
      if (i < N && j < M && S[i] == T[j]) dp[i + 1][j + 1][0] += dp[i][j][1];
    }
  mint ans = 0;
  for (long long i = 0; i < (M + 1); i++) ans += dp[N][i][0];
  cout << ans << endl;
  return 0;
}
