#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
long long N, M;
vector<long long> S, T;
vector<vector<long long>> Dp;
int main() {
  cin >> N >> M;
  S.resize(N);
  for (long long i = 0; i < N; ++i) cin >> S[i];
  T.resize(M);
  for (long long j = 0; j < M; ++j) cin >> T[j];
  Dp.resize(N + 1);
  for (auto &dp : Dp) dp.resize(M + 1);
  for (long long i = 0; i <= N; ++i) Dp[i][0] = 1;
  for (long long j = 0; j <= N; ++j) Dp[0][j] = 1;
  for (long long i = 1; i <= N; ++i) {
    for (long long j = 1; j <= M; ++j) {
      Dp[i][j] = (Dp[i - 1][j] + Dp[i][j - 1] + MOD - Dp[i - 1][j - 1]) % MOD;
      if (S[i - 1] == T[j - 1]) (Dp[i][j] += Dp[i - 1][j - 1]) %= MOD;
    }
  }
  cout << Dp[N][M] << endl;
  return 0;
}
