#include <bits/stdc++.h>
using namespace std;
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; }
bool prime(long long x) {
  for (long long i = 2; i <= sqrt(x); i++) {
    if (x % i == 0) return false;
  }
  return true;
}
long long kai(long long x) {
  if (x == 0) return 1;
  return kai(x - 1) * x % 1000000007;
}
long long mod_pow(long long x, long long y, long long mood) {
  long long res = 1;
  while (y > 0) {
    if (y & 1) {
      res = res * x % mood;
    }
    x = x * x % mood;
    y >>= 1;
  }
  return res;
}
long long comb(long long x, long long y) {
  if (y > x) return 0;
  return kai(x) * mod_pow(kai(x - y), 1000000007 - 2, 1000000007) % 1000000007 *
         mod_pow(kai(y), 1000000007 - 2, 1000000007) % 1000000007;
}
long long n, m, s[2000], t[2000];
long long dp[2010][2010];
signed main() {
  cin >> n >> m;
  for (long long i = 0; i < n; i++) cin >> s[i];
  for (long long i = 0; i < m; i++) cin >> t[i];
  dp[0][0] = 1;
  for (long long i = 1; i <= n; i++) dp[i][0] = 1;
  for (long long i = 1; i <= m; i++) dp[0][i] = 1;
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= m; j++) {
      cout << i << " " << j << endl;
      if (s[i - 1] == t[j - 1])
        dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
      else
        dp[i][j] = dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1];
      dp[i][j] += 1000000007;
      dp[i][j] %= 1000000007;
    }
  }
  cout << dp[n][m] << endl;
}
