#include <bits/stdc++.h>
using namespace std;
bool prime(long long x) {
  for (long long i = 2; i * i <= x; i++) {
    if (x % i == 0) return false;
  }
  return x > 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 kai(long long x, long long y) {
  long long res = 1;
  for (long long i = x - y + 1; i <= x; i++) {
    res *= i;
    res %= (long long)(1e9 + 7);
  }
  return res;
}
long long mod_pow(long long x, long long y) {
  long long res = 1;
  while (y > 0) {
    if (y & 1) {
      res = res * x % (long long)(1e9 + 7);
    }
    x = x * x % (long long)(1e9 + 7);
    y >>= 1;
  }
  return res;
}
long long comb(long long x, long long y) {
  if (y > x) return 0;
  return kai(x, y) * mod_pow(kai(y, y), (long long)(1e9 + 7) - 2) %
         (long long)(1e9 + 7);
}
long long n, m;
long long a[2145], b[2145];
long long dp[2145][2145];
long long ans;
signed main() {
  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 < m + 1; i++) dp[0][i] = 1;
  for (long long i = 0; i < n + 1; i++) dp[i][0] = 1;
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) {
      if (a[i] == b[j]) {
        dp[i + 1][j + 1] = dp[i][j + 1] + dp[i + 1][j];
        ans += dp[i + 1][j + 1];
        ans %= (long long)(1e9 + 7);
      } else
        dp[i + 1][j + 1] = dp[i + 1][j] + dp[i][j + 1] - dp[i][j];
      dp[i + 1][j + 1] %= (long long)(1e9 + 7);
    }
  }
  cout << dp[n][m] << endl;
}
