#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
long long dp[2010][2010];
void solve(long long N, long long M, std::vector<long long> S,
           std::vector<long long> T) {
  for (long long i = 0; i <= N; ++i) {
    dp[i][0] = 1;
  }
  for (long long i = 0; i <= M; ++i) {
    dp[0][i] = 1;
  }
  for (long long i = 0; i < N; ++i) {
    for (long long j = 0; j < M; ++j) {
      dp[i + 1][j + 1] = (dp[i + 1][j] + dp[i][j + 1] - dp[i][j]) % MOD;
      if (S[i] == T[j]) {
        (dp[i + 1][j + 1] += dp[i][j]) %= MOD;
      }
    }
  }
  cout << dp[N][M] << endl;
}
signed main() {
  long long N;
  scanf("%lld", &N);
  long long M;
  scanf("%lld", &M);
  std::vector<long long> S(N);
  for (long long i = 0; i < N; i++) {
    scanf("%lld", &S[i]);
  }
  std::vector<long long> T(M);
  for (long long i = 0; i < M; i++) {
    scanf("%lld", &T[i]);
  }
  solve(N, M, std::move(S), std::move(T));
  return 0;
}
