#include <bits/stdc++.h>
using namespace std;
const long long INF = LLONG_MAX - 100;
const long long mod = 1e9 + 7;
const long long MAX_N = 2e5 + 5;
long long dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1};
vector<long long> prime;
long long fac[MAX_N], inv[MAX_N];
template <class T = long long>
T in() {
  T x;
  cin >> x;
  return (x);
}
void DEBUG(vector<long long> a) {
  for (long long i = 0; i < a.size(); i++) cout << a[i] << " ";
  cout << endl;
}
long long GCD(long long a, long long b) {
  long long c;
  while (b != 0) {
    c = a % b;
    a = b;
    b = c;
  }
  return a;
}
long long LCM(long long a, long long b) { return a * b / GCD(a, b); }
long long POW(long long a, long long b, bool usemod = true) {
  long long c = 1LL;
  while (b > 0) {
    if (b & 1LL) {
      if (!usemod)
        c *= a;
      else
        c = a * c % mod;
    }
    if (!usemod)
      a *= a;
    else
      a = a * a % mod;
    b >>= 1LL;
  }
  return c;
}
void _nCr() {
  fac[0] = 1LL;
  for (long long i = 1LL; i < MAX_N; i++) {
    fac[i] = fac[i - 1LL] * i % mod;
  }
  for (long long i = 0; i < MAX_N; i++) {
    inv[i] = POW(fac[i], mod - 2);
  }
}
long long nCr(long long n, long long r) {
  return (fac[n] * inv[r] % mod) * inv[n - r] % mod;
}
void PRI(long long n) {
  bool a[n + 1LL];
  for (long long i = 0; i < n + 1LL; i++) {
    a[i] = 1LL;
  }
  for (long long i = 2; i < n + 1LL; i++) {
    if (a[i]) {
      prime.push_back(i);
      long long b = i;
      while (b <= n) {
        a[b] = 0;
        b += i;
      }
    }
  }
}
template <typename T>
T chmin(T& a, T b) {
  if (a > b) a = b;
  return a;
}
template <typename T>
T chmax(T& a, T b) {
  if (a < b) a = b;
  return b;
}
long long dp[2005][2005];
long long sum[2005][2005];
bool solve() {
  long long n, m;
  cin >> n >> m;
  vector<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];
  for (long long(i) = (0); (i) < (n); (i)++)
    for (long long(j) = (0); (j) < (m); (j)++) sum[i][j] = 1;
  for (long long(i) = (0); (i) < (n); (i)++) {
    for (long long(j) = (0); (j) < (m); (j)++) {
      sum[i + 1][j + 1] = sum[i][j + 1] + sum[i + 1][j] - sum[i][j];
      if (s[i] == t[j]) dp[i + 1][j + 1] = sum[i][j];
      sum[i + 1][j + 1] += dp[i + 1][j + 1] + mod;
      sum[i + 1][j + 1] %= mod;
    }
  }
  cout << sum[n][m] << endl;
}
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
}
