#include <bits/stdc++.h>
using namespace std;
inline long long mod(long long n, long long m) {
  long long ret = n % m;
  if (ret < 0) ret += m;
  return ret;
}
long long gcd(long long a, long long b) { return (b == 0 ? a : gcd(b, a % b)); }
long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); }
long long exp(long long a, long long b, long long m) {
  if (b == 0) return 1;
  if (b == 1) return mod(a, m);
  long long k = mod(exp(a, b / 2, m), m);
  if (b & 1) {
    return mod(a * mod(k * k, m), m);
  } else
    return mod(k * k, m);
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long n, m;
  cin >> n >> m;
  vector<long long> a(n), b(m);
  for (long long i = 0; i < n; i++) cin >> a[i];
  for (long long i = 0; i < m; i++) cin >> b[i];
  long long dp[n + 1][m + 1];
  for (long long i = 0; i < max(n, m) + 1; i++) dp[i][0] = dp[0][i] = 1;
  for (long long i = 1; i <= n; i++)
    for (long long j = 1; j <= m; j++)
      dp[i][j] = mod(dp[i - 1][j] + dp[i][j - 1] -
                         (a[i - 1] == b[j - 1] ? 0 : dp[i - 1][j - 1]),
                     1000000007);
  cout << dp[n][m] << "\n";
}
