#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
struct modint {
  int val;
  modint inv() const {
    int tmp, a = val, b = MOD, x = 1, y = 0;
    while (b) tmp = a / b, a -= tmp * b, swap(a, b), x -= tmp * y, swap(x, y);
    return modint(x);
  }

 public:
  modint() : val(0) {}
  modint(long long x) {
    if ((val = x % MOD) < 0) val += MOD;
  }
  modint pow(long long t) {
    modint res = 1, b = *this;
    while (t) {
      if (t & 1) res *= b;
      b *= b;
      t >>= 1;
    }
    return res;
  }
  modint& operator+=(const modint& x) {
    if ((val += x.val) >= MOD) val -= MOD;
    return *this;
  }
  modint& operator-=(const modint& x) {
    if ((val += MOD - x.val) >= MOD) val -= MOD;
    return *this;
  }
  modint& operator*=(const modint& x) {
    val = (long long)val * x.val % MOD;
    return *this;
  }
  modint& operator/=(const modint& x) { return *this *= x.inv(); }
  bool operator==(const modint& x) const { return val == x.val; }
  bool operator!=(const modint& x) const { return val != x.val; }
  bool operator<(const modint& x) const { return val < x.val; }
  bool operator<=(const modint& x) const { return val <= x.val; }
  bool operator>(const modint& x) const { return val > x.val; }
  bool operator>=(const modint& x) const { return val >= x.val; }
  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; }
};
modint dp[2001][2001];
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> ls(n), lt(m);
  for (int i = 0; i < n; ++i) {
    cin >> ls[i];
  }
  for (int i = 0; i < m; ++i) {
    cin >> lt[i];
  }
  for (int i = 0; i <= n; ++i) {
    dp[i][0] = 1;
  }
  for (int i = 0; i <= n; ++i) {
    dp[0][i] = 1;
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      dp[i + 1][j + 1] = dp[i + 1][j];
      dp[i + 1][j + 1] += dp[i][j + 1];
      if (ls[i] != lt[j]) {
        dp[i + 1][j + 1] -= dp[i][j];
      }
    }
  }
  cout << dp[n][m].val << endl;
}
