#include <bits/stdc++.h>
using namespace std;
const long long inf = (long long)1e9 + 10;
const long long linf = (long long)1e18 + 10;
const long long mod = (long long)(1e9 + 7);
const long long dx[] = {0, 1, 0, -1};
const long long dy[] = {1, 0, -1, 0};
const long long ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const long long ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;
long long mop(long long a, long long b = mod - 2, long long m = mod) {
  long long r = 1;
  a %= m;
  for (; b; b >>= 1) {
    if (b & 1) r = r * a % m;
    a = a * a % m;
  }
  return r;
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
bool ool(long long x, long long y, long long h, long long w) {
  return ((x < 0) || (h <= x) || (y < 0) || (w <= y));
}
bool deq(double a, double b) { return abs(a - b) < eps; }
struct oreno_initializer {
  oreno_initializer() {
    cin.tie(0);
    ios::sync_with_stdio(0);
  }
} oreno_initializer;
long long n, m, x[2020], y[2020], dp[2020][2020];
signed main() {
  cin >> n >> m;
  for (long long(i) = (0); (i) < (n); ++(i)) cin >> x[i];
  for (long long(i) = (0); (i) < (m); ++(i)) cin >> y[i];
  for (long long(i) = (1); (i) < (n + 1); ++(i))
    for (long long(j) = (1); (j) < (m + 1); ++(j)) {
      if (x[i - 1] == y[j - 1])
        dp[i][j] = (dp[i][j - 1] + dp[i - 1][j] + 1) % mod;
      else
        dp[i][j] = (dp[i][j - 1] + dp[i - 1][j] - dp[i - 1][j - 1]) % mod;
    }
  cout << (dp[n][m] + 1) % mod << "\n";
}
