#include <bits/stdc++.h>
using namespace std;
using P = pair<long long, long long>;
using ll = long long;
const long long INF = LLONG_MAX / 3;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
struct UnionFind {
  std::vector<long long> par, siz;
  void init(long long n) {
    par.resize(n);
    for (long long i = 0; i < n; i++) par[i] = i;
    siz.resize(n, 1);
  }
  UnionFind(long long n) { init(n); }
  long long root(long long n) {
    if (par[n] == n)
      return n;
    else
      return par[n] = root(par[n]);
  }
  bool issame(long long x, long long y) { return (root(x) == root(y)); }
  bool marge(long long a, long long b) {
    if (issame(a, b))
      return false;
    else {
      a = root(a), b = root(b);
      if (siz[a] < siz[b]) swap(a, b);
      siz[a] += siz[b];
      par[a] = par[b];
      return true;
    }
  }
  long long size(long long n) { return siz[root(n)]; }
};
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long lcm(long long i, long long j) { return i * (j / gcd(i, j)); }
const long long MOD = 1e9 + 7;
long long fac[510000], finv[510000], inv[510000];
long long MAX = 510000;
bool COMinited = false;
long long COM(long long n, long long k) {
  if (COMinited == false) {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (long long i = 2; i < MAX; i++) {
      fac[i] = fac[i - 1] * i % MOD;
      inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
      finv[i] = finv[i - 1] * inv[i] % MOD;
    }
    COMinited = true;
  }
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
long long modpow(long long a, long long n, long long mod) {
  long long res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}
long long modinv(long long a, long long mod) { return modpow(a, mod - 2, mod); }
signed main() {
  long long n, m;
  cin >> n >> m;
  long long s[1010], t[1010];
  for (long long i = (long long)0, i_len = (n); i < i_len; i++) cin >> s[i];
  for (long long i = (long long)0, i_len = (m); i < i_len; i++) cin >> t[i];
  long long dp[1010][1010];
  for (long long i = (long long)0, i_len = (n + 1); i < i_len; i++) {
    for (long long j = (long long)0, j_len = (m + 1); j < j_len; j++) {
      if (i == 0 || j == 0) {
        dp[i][j] = 1;
        continue;
      }
      dp[i][j] = (dp[i][j - 1] + dp[i - 1][j] - dp[i - 1][j - 1]) % MOD;
      if (s[i - 1] == t[j - 1]) dp[i][j] += dp[i - 1][j - 1];
      dp[i][j] %= MOD;
    }
  }
  cout << (dp[n][m] + MOD) % MOD << endl;
}
