#include <bits/stdc++.h>
using namespace std;
const uint64_t MOD = 1e+9 + 7;
int main() {
  uint64_t N, M;
  cin >> N >> M;
  vector<uint64_t> S(N), T(M);
  for (uint64_t n = 0; n < N; ++n) {
    cin >> S[n];
  }
  for (uint64_t m = 0; m < M; ++m) {
    cin >> T[m];
  }
  vector<vector<uint64_t> > dp(N + 1), sum(N + 1);
  for (uint64_t n = 0; n <= N; ++n) {
    dp[n] = vector<uint64_t>(M + 1, 0);
    sum[n] = vector<uint64_t>(M + 1, 0);
  }
  for (uint64_t n = 1; n <= N; ++n) {
    for (uint64_t m = 1; m <= M; ++m) {
      if (S[n - 1] == T[m - 1]) {
        dp[n][m] = (sum[n - 1][m - 1] + 1) % MOD;
      } else {
        dp[n][m] = 0;
      }
      sum[n][m] = (sum[n - 1][m] + sum[n][m - 1]) % MOD;
      sum[n][m] = (sum[n][m] - sum[n - 1][m - 1] + dp[n][m]) % MOD;
    }
  }
  cout << ((sum[N][M] + 1) % MOD) << endl;
  return 0;
}
