#include <bits/stdc++.h>
const long long MOD = 1e9 + 7;
signed main() {
  long long n, m;
  std::cin >> n >> m;
  std::vector<long long> s(n);
  std::vector<long long> t(m);
  for (long long i = 0; i < n; i++) std::cin >> s[i];
  for (long long i = 0; i < m; i++) std::cin >> t[i];
  std::vector<std::vector<long long> > sum(n + 1,
                                           std::vector<long long>(m + 1, 0));
  std::vector<std::vector<long long> > dp(n + 1,
                                          std::vector<long long>(m + 1, 0));
  dp[0][0] = 1;
  for (long long i = 0; i < n + 1; i++) sum[i][0] = 1;
  for (long long i = 0; i < m + 1; i++) sum[0][i] = 1;
  for (long long i = 0; i < n; i++)
    for (long long j = 0; j < m; j++) {
      if (s[i] == t[j]) {
        dp[i + 1][j + 1] = sum[i][j];
      }
      sum[i + 1][j + 1] =
          (dp[i + 1][j + 1] + sum[i][j + 1] + sum[i + 1][j] - sum[i][j]) % MOD;
    }
  std::cout << (sum[n][m]) << "\n";
  return 0;
}
