#include <bits/stdc++.h>
using ll = long long;
using P = std::pair<ll, ll>;
const ll MOD = 1e9 + 7;
ll dp[2001][2001] = {0}, sum[2001][2001] = {0};
int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  ll n, m;
  std::cin >> n >> m;
  std::vector<ll> s(n), t(m);
  for (ll(i) = (0); i < (n); i++) std::cin >> s[i];
  for (ll(i) = (0); i < (m); i++) std::cin >> t[i];
  for (ll(i) = (0); i < (n); i++)
    if (s[i] == t[0]) dp[i][0] = 1;
  for (ll(i) = (0); i < (m); i++)
    if (s[0] == t[i]) dp[0][i] = 1;
  sum[0][0] = dp[0][0];
  for (ll(i) = (1); i < (n); i++) sum[i][0] = sum[i - 1][0] + dp[i][0];
  for (ll(i) = (1); i < (m); i++) sum[0][i] = sum[0][i - 1] + dp[0][i];
  for (ll(i) = (1); i < (n); i++) {
    for (ll(j) = (1); j < (m); j++) {
      if (s[i] == t[j]) dp[i][j] = (sum[i - 1][j - 1] + 1) % MOD;
      sum[i][j] =
          (sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] + dp[i][j]) % MOD;
    }
  }
  std::cout << sum[n - 1][m - 1] + 1;
  return 0;
}
