#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ll N, M, MOD = 1e9 + 7;
  cin >> N >> M;
  vector<ll> S(N + 1, 0), T(M + 1, 0);
  vector<vector<ll>> DP(N + 1, vector<ll>(M + 1, 0)),
      sum(N + 1, vector<ll>(M + 1, 0));
  for (ll i = 1; i <= N; i++) cin >> S[i];
  for (ll i = 1; i <= M; i++) cin >> T[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;
    }
  cout << (sum[N][M] + 1) % MOD << endl;
}
