#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using R = double;
using Data = pair<ll, vector<ll>>;
template <typename T>
using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll MOD = 1e9 + 7;
const ll inf = 1LL << 60;
struct edge {
  ll from;
  ll to;
  ll cost;
};
ll dp[2020][2020];
int main() {
  ll N, M;
  cin >> N >> M;
  vector<ll> S(N), T(M);
  for (ll i = 0; i < N; ++i) cin >> S[i];
  for (ll i = 0; i < M; ++i) cin >> T[i];
  dp[0][0] = 1;
  for (ll i = 0; i < 2020; ++i) dp[i][0] = 1;
  for (ll j = 0; j < 2020; ++j) dp[0][j] = 1;
  for (ll i = 1; i < N + 1; ++i)
    for (ll j = 1; j < M + 1; ++j) {
      if (S[i - 1] == T[j - 1]) {
        dp[i][j] += dp[i - 1][j - 1];
      }
      dp[i][j] += dp[i - 1][j] + dp[i][j - 1];
      dp[i][j] -= dp[i - 1][j - 1];
      dp[i][j] %= MOD;
    }
  cout << dp[N][M] << endl;
  return 0;
}
