#include <bits/stdc++.h>
using namespace std;
template <class T>
bool chmax(T& a, const T& b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T& a, const T& b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
bool prime(long long n) {
  for (long long i = 2; i <= sqrt(n); i++) {
    if (n % i == 0) return false;
  }
  return n != 1;
}
long long gcd(long long x, long long y) {
  if (y == 0) return x;
  return gcd(y, x % y);
}
long long lcm(long long x, long long y) { return x / gcd(x, y) * y; }
long long mod_pow(long long n, long long p, long long m) {
  if (p == 0) return 1;
  if (p % 2 == 0) {
    long long t = mod_pow(n, p / 2, m);
    return (t * t) % m;
  }
  return n * mod_pow(n, p - 1, m) % m;
}
long long extGCD(long long a, long long b, long long& x, long long& y) {
  if (b == 0) {
    x = 1;
    y = 0;
    return a;
  }
  long long d = extGCD(b, a % b, y, x);
  y -= a / b * x;
  return d;
}
long long modinv(long long a, long long m) {
  long long b = m, u = 1, v = 0;
  while (b) {
    long long t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}
long long modinv2(long long a, long long mod) {
  return mod_pow(a, mod - 2, mod);
}
long long digit(long long x) {
  long long cnt = 0;
  while (x > 0) {
    cnt += x % 10;
    x /= 10;
  }
  return cnt;
}
long long read() {
  long long tmp;
  cin >> tmp;
  return tmp;
}
long long xor128() {
  static long long x = 123456789, y = 362436069, z = 521288629, w = 88675123;
  long long t = (x xor (x << 11));
  x = y;
  y = z;
  z = w;
  return (w = (w xor (w >> 19)) xor (t xor (t >> 8)));
}
map<long long, long long> factaring(long long x) {
  map<long long, long long> ans;
  long long now = 2;
  while (now * now <= x) {
    if (x % now == 0) {
      x /= now;
      ans[now]++;
    } else
      now++;
  }
  if (x != 1) ans[x]++;
  return ans;
}
long long comb(long long n, long long k, long long mod) {
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  k = min(k, n - k);
  long long x = 1, y = 1;
  for (long long i = 0; i < k; i++) {
    y *= i + 1;
    y %= mod;
  }
  for (long long i = n - k + 1; i <= n; i++) {
    x *= i;
    x %= mod;
  }
  return x * modinv(y, mod) % mod;
}
signed main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  long long n, m;
  long long a[2005], b[2005];
  long long dp[2005][2005];
  cin >> n >> m;
  for (long long i = 0; i < n; i++) cin >> a[i];
  for (long long i = 0; i < m; i++) cin >> b[i];
  for (long long i = 0; i < n + 1; i++) {
    for (long long j = 0; j < m + 1; j++) {
      dp[i][j] = 0;
    }
  }
  for (long long i = 0; i < n + 1; i++) dp[i][0] = 1;
  for (long long i = 0; i < m + 1; i++) dp[0][i] = 1;
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= m; j++) {
      dp[i][j] = dp[i][j - 1] + dp[i - 1][j] - dp[i - 1][j - 1];
      dp[i][j] %= 1000000007;
      if (a[i - 1] == b[j - 1]) {
        dp[i][j] += dp[i - 1][j - 1];
      }
      dp[i][j] %= 1000000007;
    }
  }
  cout << dp[n][m] << "\n";
  return 0;
}
