#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ll N, M;
  cin >> N >> M;
  ll MOD = 1e9 + 7;
  vector<ll> S(N + 1);
  vector<ll> T(M + 1);
  vector<vector<ll>> dp(N + 1, vector<ll>(M + 1, 0));
  vector<vector<ll>> su(N + 1, vector<ll>(M + 1, 0));
  for (int s = 1; s <= N; s++) {
    cin >> S[s];
  }
  for (int t = 1; t <= M; t++) {
    cin >> T[t];
  }
  for (ll i = 1; i <= N + M; i++) {
    for (ll j = 1; j <= M; j++) {
      ll s = i - j + 1, t = j;
      if (s < 1 || s > N) continue;
      if (S[s] == T[t]) {
        dp[s][t] = su[s - 1][t - 1] + 1;
      }
      su[s][t] =
          (su[s - 1][t] + su[s][t - 1] - su[s - 1][t - 1] + dp[s][t]) % MOD;
    }
  }
  cout << (su[N][M] + 1) << "\n";
  return 0;
}
