#include <bits/stdc++.h>
using namespace std;
const double PI = 3.14159265358979323846;
const double EPS = 1e-9;
const long long INF = 10e17;
double equal(double a, double b) { return fabs(a - b) < DBL_EPSILON; }
std::istream &operator>>(std::istream &in, set<int> &o) {
  int a;
  in >> a;
  o.insert(a);
  return in;
}
std::istream &operator>>(std::istream &in, queue<int> &o) {
  long long a;
  in >> a;
  o.push(a);
  return in;
}
bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }
const int mod = 1000000007;
struct mint {
  long long x;
  mint(long long x = 0) : x((x % mod + mod) % mod) {}
  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 {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res -= a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res *= a;
  }
  mint pow(long long t) const {
    if (!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1) a *= *this;
    return a;
  }
  mint inv() const { return pow(mod - 2); }
  mint &operator/=(const mint a) { return (*this) *= a.inv(); }
  mint operator/(const mint a) const {
    mint res(*this);
    return res /= a;
  }
  friend std::istream &operator>>(std::istream &in, mint &o) {
    long long a;
    in >> a;
    o = a;
    return in;
  }
  friend std::ostream &operator<<(std::ostream &out, const mint &o) {
    out << o.x;
    return out;
  }
};
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(n), t(m);
  for (int &i : s) cin >> i;
  for (int &i : t) cin >> i;
  vector<vector<mint>> dp(n, vector<mint>(m));
  auto get = [&](int i, int j) -> mint {
    if (i < 0) return 0;
    if (j < 0) return 0;
    return dp[i][j];
  };
  for (int i = 0; i < (n); ++i) {
    for (int j = 0; j < (m); ++j) {
      char a = s[i];
      char b = t[j];
      if (a != b) continue;
      dp[i][j] = get(i - 1, j - 1) + 1;
    }
    for (int j = 0; j < (m); ++j) dp[i][j] += get(i, j - 1);
    for (int j = 0; j < (m); ++j) dp[i][j] += get(i - 1, j);
  }
  cout << dp.back().back() + 1 << endl;
}
