#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const long long mod = 1e9 + 7;
long long X[2048], Y[2048];
long long dp[2048][2048];
long long n, m;
long long fact[2048], inv[2048], finv[2048];
void pre_calc() {
  fact[0] = fact[1] = 1;
  inv[1] = 1;
  finv[0] = finv[1] = 1;
  for (int i = 2; i < 2048; i++) {
    fact[i] = i * fact[i - 1] % mod;
    inv[i] = mod - mod / i * inv[mod % i] % mod;
    finv[i] = inv[i] * finv[i - 1] % mod;
  }
}
long long calc(long long n, long long k) {
  if (n < k || n < 0) return 0;
  return fact[n] * finv[n - k] % mod * finv[k] % mod;
}
long long solve(int i, int j) {
  if (i == n || j == m) return 0;
  if (dp[i][j] > 0) return dp[i][j];
  if (X[i] == Y[j])
    dp[i][j] = (1 + solve(i + 1, j) + solve(i, j + 1)) % mod;
  else
    dp[i][j] =
        (solve(i + 1, j) + solve(i, j + 1) - solve(i + 1, j + 1) + mod) % mod;
  return dp[i][j];
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  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];
  memset(dp, -1, sizeof dp);
  cout << (solve(0, 0) + 1) % mod << '\n';
  return 0;
}
